Grouping in store with values in extjs 6.2

帅比萌擦擦* 提交于 2019-12-11 14:42:32

问题


I am trying to group my store on department name . Department name contains some null values also . when i am trying grouping along with sort function its result in multiple group from same name.

see this fiddel for details. I am not getting what i am doing wrong. Kindly advise.


回答1:


Your sorterFn is wrong.

The sorterFn has to return three different values:

  • 1 if the second argument is strictly greater than the first.
  • -1 if the second argument is strictly smaller than the first.
  • 0 if both arguments are the same group.

Your sorterFn never returns 0. Try this one:

sorterFn: function(a, b) {
    if(a.get('department')=="Management" && b.get('department')=="Management") return 0;
    if(a.get('department')=="Management") return 1;
    if(b.get('department')=="Management") return -1;
    if(a.get('department') < b.get('department')) return 1;
    if(a.get('department') > b.get('department')) return -1;
    return 0;
},

Furthermore, your transform function is useless. It is called only from the original sorterFn, which you overwrite. You would have to account for null values in your sorterFn, if you wish so. (However, usually one would put fallback categories like "Others" in the end, not between "IT" and "Sales".)

Also, to write the department in the header line, you have to override the groupHeaderTpl template, e.g.

groupHeaderTpl: [
    '<tpl if=\'name\'>{name}<tpl else>Others</tpl>'
]


来源:https://stackoverflow.com/questions/44016618/grouping-in-store-with-values-in-extjs-6-2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!