EXTJS 5: Como classificar a coluna da grade no EXT JS 5
Atualizei recentemente a versão do EXT JS para 5 e a substituição da função doSort não funciona mais. Alguém uma idéia de como fazer?
Exemplo de substituição:
{
text: 'Custom',
sortable : true,
dataIndex: 'customsort',
doSort: function(state) {
var ds = this.up('grid').getStore();
var field = this.getSortParam();
ds.sort({
property: field,
direction: state,
sorterFn: function(v1, v2){
v1 = v1.get(field);
v2 = v2.get(field);
return v1.length > v2.length ? 1 : (v1.length < v2.length ? -1 : 0);
}
});
}
}
Editar 1: Eu apenas tentei a solução do @tomgranerod, mas o me.sortState é sempre 'indefinido'. Então, eu faço isso para atualizar minha variável:
sort: function () {
var me = this,
grid = me.up('tablepanel'),
store = grid.store;
me.sortState = me.sortState === 'ASC' ? 'DESC' : 'ASC';
Ext.suspendLayouts();
me.sorting = true;
store.sort({
property: me.getSortParam(),
direction: me.sortState,
sortFn: function (v1, v2) {
v1 = v1.get(field);
v2 = v2.get(field);
return v1.length > v2.length ? 1 : (v1.length < v2.length ? -1 : 0);
}
});
delete me.sorting;
Ext.resumeLayouts(true);
}
Mas a função sortFn nunca é chamada. Não sei porque. ===> !!!! funciona com EXT JS 5.0.1, mas a função sortFin nunca é chamada. !!!!
Edição 2: Isto é o que eu tento ter:
ASC:
if (v1 and v2 are numbers) return v1 > v2;
else if (v1 is a number and v2 a string) return false;
else if (v1 is a string and v2 a number) return true;
else if (v1 and v2 are strings) return v1 > v2;
DESC:
if (v1 and v2 are numbers) return v1 < v2;
else if (v1 is a number and v2 a string) return true;
else if (v1 is a string and v2 a number) return false;
else if (v1 and v2 are strings) return v1 < v2;