当前位置:首页 > 开发 > 编程语言 > 编程 > 正文

Ext Tree的排序

发表于: 2014-01-21   作者:ckf53390   来源:转载   浏览:
摘要: Ext.tree.LocaleTreeSorter = Ext.extend(Ext.tree.TreeSorter, {constructor:function (tree, config) { Ext.tree.LocaleTreeSorter.superclass.constructor.call(this, tree, config); var dsc = this.d

Ext.tree.LocaleTreeSorter = Ext.extend(Ext.tree.TreeSorter, {constructor:function (tree, config) {
 Ext.tree.LocaleTreeSorter.superclass.constructor.call(this, tree, config);
 var dsc = this.dir && this.dir.toLowerCase() == "desc";
 var fs = this.folderSort;
 var leafAttr = this.leafAttr || "leaf";
 this.sortFn = function (n1, n2) {
  if (fs) {
   if (n1.attributes[leafAttr] && !n2.attributes[leafAttr]) {
    return 1;
   }
   if (!n1.attributes[leafAttr] && n2.attributes[leafAttr]) {
    return -1;
   }
  }
  var ret = n1.text.localeCompare(n2.text);// text按照中文名称排序,改为id  按照id排序
  if (ret < 0) {
   return dsc ? +1 : -1;
  } else {
   if (ret > 0) {
    return dsc ? -1 : +1;
   } else {
    return 0;
   }
  }
 };
}});

 

 

今天改一个以前别人写的代码,发现树也可以设置排序,代码如下
new Ext.tree.TreeSorter(tree,{folderSort:true,dir:'desc'});

Ext Tree的排序

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号