Search code examples
extjsextjs3

How do I get a sortType for a field in an ExtJS store?


How do I get the sortType for a field in an ExtJS store?

This doesn't work:

var sortType = myStore.fields.get('MyFieldName').sortType;

Solution

  • When you pass a string as sortType then it is converted to a function in the constructor of Ext.data.Field, so you need to compare that function with available sortTypes to get the correct sortType string

    var sortTypeFn = myStore.fields.get('MyFieldName').sortType;
    var sortType = '';
    Ext.iterate(Ext.data.Types, function(key, obj) {
          if(obj.sortType == sortTypeFn) {
               sortType = key;
               return false;
          }
    });
    console.log(sortType);