【问题标题】:Selected row not highlighted in jqgridjqgrid中未突出显示的选定行
【发布时间】:2017-12-14 07:42:03
【问题描述】:

我已经编写了行选择功能。它没有突出显示选定的行(有时突出显示有时突出显示的其他行)并且没有按照我编写的方式显示图标。以下是代码 multiselect : true, iconSet: "fontAwesome", datatype : "json", loadonce : true, rowNum : 10, rowList : [ 10, 20, 30 ], toppager:true, pager : '#prowed1', sortname : 'id', viewrecords : true, sortorder : "asc", editurl : "editGrid.html", onSelectRow : function(rowId) { var rowId = jQuery("#list1").jqGrid('getGridParam', 'selarrrow'); if (rowId.length > 1) { $("#list1_iledit").addClass('ui-state-disabled'); } },

$("#list1").jqGrid(
            "navGrid",
            "#prowed1",
            {
                cloneToTop:true,
                formatter : "checkboxFontAwesome4",
                 addicon:"fa fa-plus ",
                add : true,
                delicon:"fa fa-trash",
                del : true,
                searchicon:"fa fa-search",
                search : true,
                refreshicon:"fa fa-refresh",
                refresh : true,
                editicon:"fa fa-edit ",
                edit : true,
                saveicon : 'fa fa-floppy-o',
                save : true,

            },`{ // edit options
                afterSubmit : function() {
                    location.reload(true);
                },
                beforeShowForm : function(form) {
                    $("td .navButton navButton-ltr").hide();
                },
                closeAfterEdit : true
            },
            { // add options
                beforeShowForm : function(form) {
                    $("#buName").removeAttr("readonly");
                },
                closeAfterAdd : true,
                clearAfterAdd : true
            },
            { // del options
                serializeDelData : function(postdata) {
                    return {
                        'buName' : $('#list1').jqGrid('getCell',
                                postdata.id, 'buName'),
                        'oper' : 'del'
                    }
                }
            }

    );` $("#list1").jqGrid('inlineNav', "#prowed1", {
        //cloneToTop:true,
        //iconSet: "fontAwesome",
        add : false,
        edit : true,
        editicon : 'fa fa-pencil-square-o',
        save : true,
        saveicon : 'fa fa-floppy-o',
        editParams : {
            aftersavefunc : function(id) {
                jQuery('#list1').jqGrid('setSelection', id, false);
            },
        },
    });`

【问题讨论】:

  • 您应该提供演示,它会重现问题。高亮问题最多的原因:输入数据错误或错误colModel。 jqGrid 的每一行总是有id 属性(rowid),它应该是输入数据的一部分:见here。 id 值必须是唯一的。如果您有重复的 id,那么您可能会遇到选择/突出显示行的问题。
  • 是的,它有 id 的问题。它包含重复的 id。那么我应该如何删除它?因为我从数据库中获取数据,所以我无法更改 id。我的意思是我应该添加哪个代码?

标签: html jqgrid


【解决方案1】:

您应该提供重现问题的演示。突出显示问题最多的原因:输入数据错误或错误colModel。 jqGrid 的每一行都有 id 属性(rowid),它应该是输入数据的一部分:参见here。 id 值必须是唯一的。如果您有重复的 id,那么您可能会遇到选择/突出显示行的问题。

如果您从数据库中填充数据,则可以使用数据库表中的本机 id 来构建唯一的 rowid。数据库表也不允许 id 重复。

为了能够编辑数据库中的数据,您需要识别已编辑的数据。这样的唯一值可以用作rowid。如果您通过 JOIN 从多个表中填充网格,则可以使用 composed id。例如,如果您使用来自两个表 User 和 Location 的数据填充网格,则 paar (user_id, location_id) 是唯一的。如果 user_id 和 location_id 都是数字,那么您可以使用 user_id + "_" + location_id 作为 rowid。该值将在编辑期间发送到服务器,您将拥有完整的信息来查找表中需要修改的数据。

【讨论】:

    【解决方案2】:

    我认为您在数据中的唯一 ID 存在问题。检查您在网格中插入数据时使用的 id 是否唯一,并且您没有重复的。

    亲切的问候

    【讨论】:

      【解决方案3】:

      在您的ColModel 中,确保属性key:true 仅指定一次并表示唯一的行ID 值。见http://www.trirand.com/jqgridwiki/doku.php?id=wiki:colmodel_options

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-02-26
        • 2016-02-15
        • 2013-12-20
        • 2011-06-16
        • 1970-01-01
        相关资源
        最近更新 更多