【问题标题】:ExtJs 3 TreePanel Sorting not workingExtJs 3 TreePanel 排序不起作用
【发布时间】:2013-06-06 06:36:30
【问题描述】:

我将Ext.ux.tree.TreeGrid 用于树形网格面板。除排序外,一切正常。 我有 3 个层次结构,比如 - 父母 - 孩子 - 孙子。我只想根据父母的文本进行排序。但我每次都得到随机结果。 :(

这是我的代码 -

var tree_grid = new Ext.ux.tree.TreeGrid({
        title : 'Requirements',
        height : 415,
        enableDD : true,
        enableHdMenu : true,
        id : 'req_tree',
        columns : [ {
            header : 'Entity',
            dataIndex : 'text',
            width : 200,
            sortable: true,
            sortType : 'asText'
        }, {
            header : 'Text',
            width : 50,
            dataIndex : 'temp',
            align : 'center',
            // sortType : 'asFloat',
            sortable: false
        }],
        dataUrl : 'my_page.php'
});

为了排序,我试过这个 -

1) var myTreeSorter = new Ext.tree.TreeSorter(tree_grid, {});
   myTreeSorter.doSort(tree_grid.getRootNode());
2) new Ext.ux.tree.TreeGridSorter(tree_grid, {
     folderSort: true,
     dir: "desc",
     sortType: function(node) {
         // sort by a custom, typed attribute:
         return parseInt(node.id, 10);
     }
 });


3) Used Attributes like - sortType, sortable, sortInfo.

然而,以上都没有帮助我。请帮忙。

【问题讨论】:

    标签: sorting extjs treegrid


    【解决方案1】:
        var mySortStore = Ext.create("Ext.data.Store", {
            model: "MyTreeStore",
            data:  []
        });
    
    Then when you go to add the node to the tree, use this function instead:
    
    function addNodeSorted(node, childToBeAdded){
        //clear the store from previous additions
        mySortStore.removeAll();
        //remove old sorters if they are dynamically changing
        mySortStore.sort();
        //add the node into the tree
        node.appendChild(childToBeAdded);
        var cn = node.childNodes,
            n;
    
        //remove all nodes from their parent and add them to the store
        while ((n = cn[0])) {
            mySortStore.add(node.removeChild(n));
        }
    
        //then sort the store like you would normally do in extjs, what kind of sorting you want is up to you
        mySortStore.sort('height', 'ASC');//this is just an example
    
        //now add them back into the tree in correct order
        mySortStore.each(function(record){
            node.appendChild(record);
        });
    }
    

    【讨论】:

      【解决方案2】:

      您是否尝试在商店中使用配置 folderSort

      TreeGrid 示例:sencha TreeGrid

      var store = Ext.create('Ext.data.TreeStore', {
              model: 'Task',
              proxy: {
                  type: 'ajax',
                  //the store will get the content from the .json file
                  url: 'treegrid.json'
              },
              **folderSort: true**
          });
      

      --

      其他解决方案,可以在商店中使用排序过滤器:

      商店排序:sencha sort

      //sort by a single field
      myStore.sort('myField', 'DESC');
      
      //sorting by multiple fields
      myStore.sort([
          {
              property : 'age',
              direction: 'ASC'
          },
          {
              property : 'name',
              direction: 'DESC'
          }
      ]);
      

      【讨论】:

      • 我的树面板没有使用商店。!我正在使用 DataURL。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-09
      • 2013-07-07
      相关资源
      最近更新 更多