2

我正在使用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.

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

4

2 回答 2

2
    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);
    });
}
于 2014-11-04T06:18:50.420 回答
0

您是否尝试过在商店中使用 config 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**
    });

--

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

店铺排序:煎茶排序

//sort by a single field
myStore.sort('myField', 'DESC');

//sorting by multiple fields
myStore.sort([
    {
        property : 'age',
        direction: 'ASC'
    },
    {
        property : 'name',
        direction: 'DESC'
    }
]);
于 2013-06-06T07:10:55.973 回答