jqgrid:如何根据所选行中的列值设置工具栏选项

我有一个列字段types的值(可编辑,只读)。 所有的行都会有这些值中的一个填充。

我想要启用/禁用toolbaroption编辑只有列值是可编辑选定的行。

我怎么能实现在jqgrid。

如果我理解您正确,您希望根据所选行启用/禁用导航器的“编辑”或“删除”button。 所以你会有 在这里输入图像描述

如果未select行或所选行不可编辑或标准导航器工具栏 在这里输入图像描述

如果该行是可编辑的。

“可编辑”或“只读”列的标准看起来是错的,因为它是列上的标准列而不是行,但是您可以轻松实现自定义标准。

实施可能是

var myGrid = jQuery("#list"); myGrid.jqGrid({ /* definition of jqGrid */ beforeSelectRow: function(rowid) { var selRowId = $(this).getGridParam('selrow'), tr = $("#"+rowid); // you can use getCell or getRowData to examine the contain of // the selected row to decide whether the row is editable or not if (selRowId !== rowid && !tr.hasClass('not-editable-row')) { // eneble the "Edit" button in the navigator $("#edit_" + this.id).removeClass('ui-state-disabled'); $("#del_" + this.id).removeClass('ui-state-disabled'); } else { // unselect previous selected row // disable the "Edit" and "Del" button in the navigator $("#edit_" + this.id).addClass('ui-state-disabled'); $("#del_" + this.id).addClass('ui-state-disabled'); } return true; // allow selection or unselection }, loadComplete: function() { // just one example how to mark some rows as non-editable is to add // some class like 'not-editable-row' which we test in beforeSelectRow $("tr.jqgrow:even",this).addClass('not-editable-row'); } }).jqGrid('navGrid','#pager'); // disable "Edit" and "Delete" button at the beginning $("#edit_" + myGrid[0].id).addClass('ui-state-disabled'); $("#del_" + myGrid[0].id).addClass('ui-state-disabled'); 

要启用/禁用“Edit”和“Del”button,我们在导航器工具栏的button上添加/删除“ui-state-disabled”类。 在上面的代码中,我将所有包含偶数的行标记为“不可编辑”。 在你的情况下,你可以使用任何其他更有意义的标准。

你可以在这里看到演示。