是否可以让JQGrid Tree使用OnSelectRow来扩展节点

问题描述 投票:0回答:1

当前,该jq树网格能够通过单击treeIcons来扩展节点。是否可以通过使用onSelectRow增强能够扩展节点的网格?

感谢您的任何帮助。

        $("#Grid1").jqGrid({
        datatype: "jsonstring",
        height: "auto",
        loadui: "disable",
        colNames: ['Category', 'ID', 'Name'],
        colModel: [
            {
                name: 'Category', index: 'Category', width: 450, sortable: false
            },
            {
                name: 'ID', index: 'ID', width: 200, align: "center", sortable: false

            },
            { name: 'Name', index: 'Name', width: 200, align: "center", sortable: false },         
        ],
        jsonReader: {
            repeatitems: false,
            root: "root"
        },
        rowattr: function (rd) {
            if (rd.parent === null) {
                return { "class": "myParentClass" };
            }
        },
        treeIcons: { leaf: 'ui-icon-blank' },
        treeGrid: true,
        treeGridModel: "adjacency",
        ExpandColumn: "Period",
        viewrecords: true,
        loadonce: false,
        search: false,
        multiSort: false,
        loadComplete: function () {
            $("#Grid1 .ui-jqgrid .ui-widget-header").addClass('myheaderclass');
            $("#Grid1 tr.jqgrow:odd").addClass('myOddAltRowClass');
            $("#Grid1 tr.jqgrow:even").addClass('myAltRowClass');
        }
});
    $("#Grid1").jqGrid('setGridParam', { datastr: totalValue });
    $("#Grid1").trigger('reloadGrid');
});
javascript c# free-jqgrid
1个回答
0
投票

这是可能的,但是代码已在Guriddo jqGrid中进行了测试,我不知道这是否可以在您使用的free-jqgrid上运行。您可以尝试一下。

  1. 请确保将ExpandColClick选项设置为false。

  2. 使用以下代码:

            onSelectRow : function( rowid ) {
                if(rowid) 
                {
                    var ind =$.jgrid.stripPref(this.p.idPrefix,rowid),
                    pos = this.p._index[ind],
                    isLeaf = this.p.treeReader.leaf_field,
                    expanded = this.p.treeReader.expanded_field;
                    if(!this.p.data[pos][isLeaf]){
                        if(this.p.data[pos][expanded]){
                            $(this).jqGrid("collapseRow",this.p.data[pos]);
                            $(this).jqGrid("collapseNode",this.p.data[pos]);
                        } else {
                            $(this).jqGrid("expandRow",this.p.data[pos]);
                            $(this).jqGrid("expandNode",this.p.data[pos]);
                        }
                    }                       
                } 
            },
    

享受

© www.soinside.com 2019 - 2024. All rights reserved.