EXTJS 5: So sortieren Sie Rasterspalten in EXT JS 5
Ich habe kürzlich die Version von EXT JS auf 5 aktualisiert und das Überschreiben der DoSort-Funktion funktioniert nicht mehr. Jemand eine Idee, wie es geht?
Beispiel für die Außerkraftsetzung:
{
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);
}
});
}
}
Bearbeiten 1: Ich probiere einfach die Lösung von @tomgranerod aus, aber der me.sortState ist immer 'undefiniert'. So aktualisiere ich meine Variable:
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);
}
Die Funktion sortFn wird jedoch nie aufgerufen. Ich weiß nicht warum. ===> !!!! es funktioniert mit EXT JS 5.0.1, aber die sortFin-Funktion wird immer nie aufgerufen. !!!!
Bearbeiten 2: Das versuche ich zu haben:
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;