我正在尝试按部门名称对我的商店进行分组。部门名称也包含一些空值。当我尝试与排序功能一起分组时,它会导致来自同名的多个组。
有关详细信息,请参阅此fiddel。我没有得到我做错了什么。好心提醒。
你的 sorterFn 是错误的。
1
如果第二个参数严格大于第一个参数。-1
如果第二个参数严格小于第一个参数。0
如果两个参数是同一组。您的 sorterFn 永远不会返回0
。试试这个:
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”和“销售”之间。)
此外,要在标题行中写入部门,您必须覆盖groupHeaderTpl
模板,例如
groupHeaderTpl: [
'<tpl if=\'name\'>{name}<tpl else>Others</tpl>'
]