【问题标题】:Is it possible to let JQGrid Tree use OnSelectRow to expand nodes是否可以让 JQGrid Tree 使用 OnSelectRow 展开节点
【发布时间】:2019-09-24 00:38:25
【问题描述】:

目前这个 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】:

    这是可能的,但是代码是在 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]);
                          }
                      }                       
                  } 
              },
      

    享受

    【讨论】:

    • @MannersW 很高兴为您提供帮助!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-31
    • 2014-07-24
    • 1970-01-01
    • 2012-03-05
    • 1970-01-01
    • 2010-12-15
    相关资源
    最近更新 更多