【问题标题】:How to prevent selecting a dropdown based on cell value condition in Jqgrid如何防止在Jqgrid中根据单元格值条件选择下拉列表
【发布时间】:2017-08-18 09:16:02
【问题描述】:

我正在尝试突出显示Red 中的单元格,无论哪个值与我的预定义值不匹配 和 1. i want to get the count of red cells in each row in the columnError_cells_Count,现在在演示页面中我手动输入了计数 2. and i want to prevent user from selecting the dropdown in status column if the row has any red cells。 我设法突出显示单元格。 请帮助获取Error_cells_Count 列中的红细胞计数并防止用户选择下拉菜单。 这是我的演示页面http://jsfiddle.net/h8Lzgh7d/27/ jqgrid版本版本是4.14.0 并且还请建议是否有可能使用字典值替换红细胞值来使用预定义字典并自动更正红细胞

【问题讨论】:

    标签: jqgrid


    【解决方案1】:

    首先,我建议您使用cellattr 在单元格上设置任何 CSS 属性。您可以使用定义为 functioneditable 的秒数来允许编辑单元格,具体取决于您的某些自定义条件(有关详细信息,请参阅 the wiki article)。

    固定的演示可能是以下https://jsfiddle.net/OlegKi/h8Lzgh7d/30/。它使用以下代码:

    var hilightcolorcell=["PURPLE","PINK","GREEN"];
    var hilightcahractercell=["Character 1","Character 2","Character 3"];
    
    jQuery("#rowed5").jqGrid({
        datatype: "local",
        shrinkToFit: false,
        data: mydata,
        height: 320,
        autowidth:true,
        colNames:['RowID','Error_Cells_Count','status','note','color_name','character_name','Variant ID'],
        colModel: [ 
            {name:'id', width:55, sorttype:"int",align:"center",frozen:true},
            {name:'Error_Cells_Count', width:100, sorttype:"int",
                align:"center",frozen:true,
                cellattr: function (rowid, cellValue) {
                    if (cellValue != null) {
                        var value = parseInt(cellValue, 10);
                        return " class='" +
                            (value > 0 ? "redcells" : "greencells") +
                            "'";
                    }
                }},
            {name:'status', width:100,
                editable: function (options) {
                    var item = $(this).jqGrid("getLocalRow", options.rowid);
                    return (item.Error_Cells_Count == null || item.Error_Cells_Count <= 0) &&
                        $.inArray(item.color_name, hilightcolorcell) >= 0 &&
                        $.inArray(item.character_name, hilightcahractercell) >= 0;
                },
                edittype:"select",editoptions:{value:"Approve:Approve"}},
            {name:'note',width:100, sortable:false,editable: true,
                edittype:"textarea", editoptions:{rows:"2",cols:"10"}},
            {name:'color_name',
                cellattr: function (rowid, cellValue) {
                    if ($.inArray(cellValue, hilightcolorcell) < 0) {
                        return " class='redcells'";
                    }
                }},
            {name:'character_name',
                cellattr: function (rowid, cellValue) {
                    if ($.inArray(cellValue, hilightcahractercell) < 0) {
                        return " class='redcells'";
                    }
                }},
            {name:'v_id'}
        ],
        cmTemplate: { width:110 }, // define default properties for colModel
        editurl: "functions.php",
        cellEdit: true,
        cellsubmit: 'remote',
        cellurl: 'functions.php',
        searching: {
            stringResult: true,
            searchOnEnter: false,
            defaultSearch : "cn"
        }
    }).jqGrid("setFrozenColumns")
        .jqGrid("filterToolbar");
    

    【讨论】:

    • 先生,请您建议如何获取列中每一行的红色单元格计数
    • @davidb:如果你使用datatype: "local",那么你可以在创建jqGrid之前在一个简单的for循环中计算红细胞的数量。您可以使用footerrow: trueuserDataOnFooter: trueuserData 参数在jqGrid 中创建页脚并在页脚中放置所需的信息。见jsfiddle.net/OlegKi/h8Lzgh7d/31
    • 非常感谢您提供非常宝贵的详细信息
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-25
    • 2021-09-05
    相关资源
    最近更新 更多