Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/416.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 可以让JQGrid树使用OnSetrow来扩展节点吗_Javascript_C#_Free Jqgrid - Fatal编程技术网

Javascript 可以让JQGrid树使用OnSetrow来扩展节点吗

Javascript 可以让JQGrid树使用OnSetrow来扩展节点吗,javascript,c#,free-jqgrid,Javascript,C#,Free Jqgrid,目前,这个jq树网格可以通过单击树图标来扩展节点。是否可以通过使用OnSetrow增强网格以扩展节点 感谢您的帮助 $("#Grid1").jqGrid({ datatype: "jsonstring", height: "auto", loadui: "disable", colNames: ['Category', 'ID', 'Name'], colModel: [ {

目前,这个jq树网格可以通过单击树图标来扩展节点。是否可以通过使用OnSetrow增强网格以扩展节点

感谢您的帮助

        $("#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');
});

这是可能的,但是代码是在Guriddo jqGrid中测试的,我不知道这是否能在您使用的免费jqGrid上工作。你可以试试看

确保ExpandColClick选项设置为false

使用以下代码:

        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]);
                    }
                }                       
            } 
        },

享受

@MannersW很乐意帮忙!