jqGrid可排序行,只允许对某些行进行排序
jqGrid Sortable Rows, only allow sorting on certain rows
我有一个启用了SortableRows
选项的jqGrid。以前我一直允许总是对行进行排序。当删除行时,数据库将通过ajax调用进行更新。为此,我一直在使用update
选项。
现在我需要实现对某些行不允许的排序。即那些对于某个可见列具有列值"1"的行。我已经成功地阻止了ajax更新,但从视觉上看,行仍然被丢弃在新位置。我需要直观地将行还原到原始位置。
到目前为止,我已经有了这段代码,它很有效,但带注释的区域是我在如何将行恢复到上一个位置方面陷入困境的地方。
jQuery("#all_driver_runs").jqGrid('sortableRows', {
update: function (ev, ui) {
//first check the value of the 'placed_in_runs' column
if ($('#all_driver_runs').jqGrid('getRowData', ui.item[0].id)['placed_in_run'] !== "1") { //here update the database
if (!ui.item[0].previousSibling) {
$.post("scripts/update_driver_run_sort.php", {
this_one: ui.item[0].id,
prev: 'none',
next: ui.item[0].nextSibling.id
});
} else if (!ui.item[0].nextSibling) {
$.post("scripts/update_driver_run_sort.php", {
this_one: ui.item[0].id,
prev: ui.item[0].previousSibling.id,
next: 'none'
});
} else {
$.post("scripts/update_driver_run_sort.php", {
this_one: ui.item[0].id,
prev: ui.item[0].previousSibling.id,
next: ui.item[0].nextSibling.id
});
}
} else {
/*
*no DB update, and now I need to revert to previous position here ???
*/
}
}
});
由于sortableRows
与jQueryUI的可排序小部件兼容,因此在加载行时可以通过向行添加一个类,然后在sortableRows
选项的items
(或cancel
)成员中指定它来阻止行进行排序。
因此,假设类是unmovable
,您可以将".jqgrow:not(.unmovable)"
传递给sortableRows
。例如:
$('#all_driver_runs').jqGrid('sortableRows', {
items: ".jqgrow:not(.unmovable)",
/* remaining options if needed */
});
要想在一行中添加一个类,请参阅以下答案。
相关文章:
- jqGrid可排序行,只允许对某些行进行排序
- jQuery jqGrid中的事件前排序
- 是否可以在JqGrid中按字母顺序以外的其他方式对组进行排序
- jqGrid不工作排序进程不工作
- JQgrid 对 ID 列的数据更改进行排序
- jqgrid:基于两列排序
- JQGrid:排序和自定义格式化程序
- 是否可以按当前排序顺序获取跨多个页面的所有 jqGrid 行
- jqGrid 显示排序后Col/hideCol不起作用
- 在单元格中显示另一个值时,按一个值对jqGrid进行排序
- jqGrid使用JsonString JsonReader实现服务器端排序分页过滤
- JQGrid在列排序时丢失记录
- jqGrid-拖动一行进行排序会打乱单元格宽度
- 奇怪的排序jqGrid
- jqGrid表单编辑选择排序
- 多列排序-Jqgrid
- jqGrid 树网格日期排序无法正常工作
- jqGrid:禁用排序
- 自定义排序jqgrid
- 服务器端排序JQGrid-Sort按钮不工作