View Full Version : Custom sort types not applied to model??

28 Jun 2013, 9:10 AM
In my app init function, I'm defining some a custom sort types, which I'm setting on some fields in my model. I never saw those sort functions called. When I inspected the model class at runtime, I saw that the sortType on the fields was 'undefined'

App Code:

init: function (app) {
Ext.apply(Ext.data.SortTypes, {
// it looks like these are never called??
asMySort: function(v) { ..... }

Model code:

Ext.define('My.model.data', {
extend: 'Ext.data.model'
fields: [
{ name:'fieldWithCustomSortType', sortType: 'asMySort' },

this is a snip from a chrome console, inspecting the model.class.fields.items array. You can see that the field that should have the custom sort type has NO sort type at all

19: constructor

convert: undefined
name: "normalField"
originalIndex: 19
sortType: function (s) {
type: Object
__proto__: TemplateClass

20: constructor

convert: undefined
name: "fieldWithCustomSortType"
originalIndex: 20
sortType: undefined
type: Object
__proto__: TemplateClass

any ideas??

28 Jun 2013, 9:50 AM
...and to make things even weirder, I can see my custom sort function when I inspect the Ext.data.SortTypes singleton

Ext.data.SortTypes: constructor

asMySort: function (key) {

arguments: null
caller: null
length: 1
name: ""
prototype: Object
__proto__: function Empty() {}
<function scope>

28 Jun 2013, 11:50 AM
Looks like a timing problem.

You're adding your custom sort type in init, which I'd imagine is running after you've defined the model. Just create the sort type before you define the model and everything should work fine.