2013-12-16 89 views
2

我有一个jqGrid,可以启用SortableRows选项。以前我一直在允许行总是被排序。当行被删除时,数据库通过ajax调用进行更新。要做到这一点,我一直在使用update选项。jqGrid可排序的行,只允许在某些行上排序

现在我需要实现排序,不允许某些行。即那些对于可见列之一具有列值“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 ??? 
      */ 
     } 
    } 
}); 

回答

4

由于sortableRows与jQueryUI的的可排序插件兼容,则可以当通过添加类的行,然后在的所述items(或cancel)成员指定它加载它们阻止来自被排序的行sortableRows'选项。

所以,假设类是unmovable,你可以通过".jqgrow:not(.unmovable)"sortableRows。例如:

$('#all_driver_runs').jqGrid('sortableRows', { 
    items: ".jqgrow:not(.unmovable)", 
    /* remaining options if needed */ 
}); 

为了一类添加到行,看到这个answer

+1

这是一些很好的东西,感谢您的帮助!完美的作品。 –

+0

我遇到了这个设置的问题。现在,如果你有两个彼此相邻的不可移动的行,那么就不可能在它们之间放置一个可移动的行。我仍然希望能够在两个不可移动的行之间放置一个可移动的行。 –

+1

查看'取消'成员。检查[这个小提琴](http://jsfiddle.net/ssarabando/C58z8/)。 “DSK1”列在“APPR”不可用时不可用。尝试移动“APPR”,看看是否你想要的。 – ssarabando