我有一个启用了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 ???
*/
}
}
});
答案 0 :(得分:4)
由于sortableRows
与jQueryUI的可排序窗口小部件兼容,因此在加载行时可以通过向行添加类然后在items
(或{cancel
中指定行来阻止行进行排序。 {1}})sortableRows
'选项的成员。
因此,假设该课程为unmovable
,您可以将".jqgrow:not(.unmovable)"
传递给sortableRows
。例如:
$('#all_driver_runs').jqGrid('sortableRows', {
items: ".jqgrow:not(.unmovable)",
/* remaining options if needed */
});
要将某个类添加到行中,请参阅此answer。