问题描述
我正在尝试按部门名称对商店进行分组.部门名称也包含一些空值.当我尝试使用排序功能进行分组时,其结果将导致多个来自相同名称的组.
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.
推荐答案
您的sorterFn错误.
Your sorterFn is wrong.
-
1
,如果第二个参数严格大于第一个参数. -
-1
,如果第二个参数严格小于第一个参数. -
0
如果两个参数是同一组.
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.
您的sorterFn从不返回0
.试试这个:
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;
},
此外,您的transform
函数无效.仅从原始的sorterFn
中调用它,然后将其覆盖.如果需要,您必须在sorterFn中考虑空值. (但是,通常通常将诸如其他"之类的后备类别放在最后,而不是在"IT"和销售"之间.)
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".)
此外,要在标题行中写部门,您必须覆盖 groupHeaderTpl
模板,例如
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>'
]
这篇关于使用extjs 6.2中的值对存储区进行分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!