jqGrid - 内联编辑 - 检测脏/更改的单元格
有没有使用 jqgrid 的 getChangedCells 的示例 判断数据是否改变的方法?
我在可下载的演示中 grep getChangedCells jqgrid,只能找到函数定义,找不到 getChangedCells 的示例用法。
我想要做的是保存用户的编辑 如果用户单击另一行则生成。但是,我只 如果该行是脏的,则想要提交保存。
提前致谢, ——内特
is there an example of using jqgrid's getChangedCells
method to determine if data has changed?
I grepped getChangedCells in the downloadable demos for
jqgrid, and could only find the function definition, not
example usages of getChangedCells.
What I want to do is save the edits that a user's
made if the user clicks on another row. But, I only
want to submit the save if the row is dirty.
Thanks in advance,
--Nate
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
该行上没有安全脏标志。您可以使用以下事实:在行编辑开始时(在 内联编辑模式)方法editRow 将
editable="1"
属性添加到网格行(元素)。后来的方法 saveRow 和 restoreRow 更改属性值为
editable="0"
。因此,当前页面中至少处于内联编辑模式一次的行将具有editable
属性。如果表元素的 id 是“list”,您可以使用 查找编辑的行。集合元素的 id 是行的 rowid。
如果您在网格中使用分页,则应小心并在更改页面之前保存当前页面上已编辑行的 id。 onPaging 事件可以帮助您。
在我看来,最好、最安全的方法是使用 editRow 或 saveRow 方法(可能您只直接使用 editRow)。在
aftersavefunc
函数内部,您可以将修改行的 id 保存在数组/映射中。这将解决您的问题并保证安全工作。There are no safe dirty flag on the row. You can use the fact that at the beginning of row editing (at the start of the inline editing mode) the method editRow add
editable="1"
attribute to the grid row (<tr>
element). Later the methods saveRow and restoreRow changes the attribute value toeditable="0"
. So the rows of the current page which was at least once in the inline editing mode will have theeditable
attribute. If the id of the table element is "list" you can find the edited rows withThe ids of the elements of the set are the rowids of the rows.
If you use paging in the grid you should be careful and save the ids of the edited rows on the current page before the changing of the page. The onPaging event would help you here.
In my opinion the best and the most safe way to do what you need is to use
aftersavefunc
parameter of the editRow or saveRow methods (probably you use directly only editRow). Inside of youraftersavefunc
function you can save the id of the modified row in an array/map. This will solve your problem and will safe work.最后,我设法带来了一段代码来检测我们想要的内容;)
希望那里有jqgrid大师(例如Oleg) ,有足够的时间来审查这段代码并改进它。
示例代码将用于检测具有名为“name”的可编辑字段的网格中更改的数据。如果您想检查更多列中的更改数据,则必须添加与该列关联的变量
after_edit
和before_edit
。为了获取
onSelectRow
函数中的先前单元格数据,我没有使用getCell
方法,因为文档中用红色表示:通过耻辱,我可以检查文档是否正确:(。
但是,
getCell
函数可以正常处理当前单元格数据。这是代码:
Finally, I managed to bring a piece of code to detect what we want ;)
Hopefully any jqgrid gurus there (like Oleg), have enough time to review this code and improve it.
The example code will work for detect data changed in a grid with an editable field named "name". If you want to check for changed data in more columns, you have to add the variables
after_edit
andbefore_edit
asociated with that columns.To get the previous cell data inside the
onSelectRow
function, I don't used thegetCell
method because in the documentation says in red:By disgrace I could check that the documentation was right :(.
However the
getCell
function works properly with the current cell data.And here is the code:
在我的一个项目中,我执行了以下操作:在编辑行之前,我记住全局变量中的行数据,编辑完成后,只需检查行数据是否已更改。像这样的东西(双击激活编辑模式):
var beforeEditData;
In one of my projects I did the following: before editing the row I remember row data in global variable and after editing is done just check if row data was changed. Something like this (edit mode activated by double click):
var beforeEditData;
所做的。
视图中
使用 MVC4 和 JQuery,这就是我在模型中的
gridInitialized 代码用于处理搜索过滤器的更改。
戴夫
Using MVC4 and JQuery this is what I did
In the View
in the Model
The gridInitialised code is to handle changes to the search filter.
Dave
正如 Oleg 在 5(哇)年前提到的 - 我使用了 saveRow 函数并将标志作为
extraparam
传递。像这样,假设你的“模型”或隐藏列
IsDirty
在我的情况下:然后循环浏览“保存”单击的行(在我的情况下为外部按钮),大致如下:
As Oleg mentioned 5 (wow) years ago - I used the saveRow function and passed the flag as
extraparam
.something like this, assuming your "model" or a hidden column
IsDirty
in my case:and then loop through the rows on Save click (external button in my case), something along the lines of: