jqgrid:如何根据所选行中的列值设置工具栏选项 [英] jqgrid: how to set toolbar options based on column value in row selected

查看:107
本文介绍了jqgrid:如何根据所选行中的列值设置工具栏选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有值(可编辑,只读)的列字段类型.所有行将填充这些值之一.

I have a column field type having values (editable, readonly). all the rows will have one of these values populated.

仅当列值对于所选行是可编辑的时,我才想启用/禁用工具栏选项编辑.

I want to enable/disable toolbaroption edit only if column value is editable for selected row.

我如何在jqgrid中实现这一目标.

how can i achieve that in jqgrid.

推荐答案

如果我了解您的意见,则您要基于选定的行启用/禁用导航器的编辑"或删除"按钮.这样你就会有

If I understand you correct you want to enable/disable "Edit" or "Delete" buttons of the navigator based of the selected row. So that you will have

如果未选择任何行,或者所选行是不可编辑的,或者是标准导航器工具栏

if no rows is selected or the selected row is non-editable or the standard navigator toolbar

如果该行是可编辑的.

可编辑"列还是只读"列的条件似乎对我来说是错误的,因为它是列上的条件列而不是行上的条件列,但是您可以轻松实现自己的自定义条件.

The criteria whether the column "editable" or "readonly" seems me wrong because it is criteria column on the column and not on the row, but you can implement easy your own custom criteria.

实施方式可能是

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');

要启用/禁用编辑"和删除"按钮,我们在导航器工具栏的按钮上添加/删除了"ui-state-disabled"类.在上面的代码中,我将所有带有偶数的行标记为不可编辑".根据您的情况,您可以使用其他更有意义的标准.

To enable/disable the "Edit" and "Del" buttons we add/remove the 'ui-state-disabled' class on the buttons of the navigator toolbar. In the code above I mark all rows with even numbers as "non-editable". In your case you can use any other criteria which has more sense.

您可以在此处观看演示.

这篇关于jqgrid:如何根据所选行中的列值设置工具栏选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆