View Full Version : Reverse Mapping Ext.data.Field

11 Apr 2012, 11:30 AM
Our naming conventions for objects and database fields are not the same. Objects are camelcased and our database fields are underscored. The mapping property in Ext.data.Field is useful in some scenarios, but not for remote operations.

I'm in the habit of adding a listener to transform sorter and filter properties beforeprefetch and beforeload. Values are transformed per a custom rmapping property that I've added to each field.

For example...

Ext.define('Project.model.Example', {
extend: 'Ext.data.Model'
,fields: [
{ name: 'id', rmapping: 'id', type: 'int' }
,{ name: 'someField', rmapping: 'some_field', type: 'string' }

Ext.define('Project.controller.Example', {
extend: 'Ext.app.Controller'

,init: function() {

this.getExampleStore().addListener('beforeload',this.mapExampleGrid, this);

,mapExampleGrid: function(store, operation, options) {
var fields = this.getExampleStore().getProxy().getModel().prototype.fields.items,
sorters = operation.sorters;

Ext.Array.each(sorters, function(sorter, index) {
Ext.Array.each(fields, function(field, index) {
if (sorter.property == field.name) {
sorter.property = field.rmapping;

How is this commonly handled? Is there a better way?

11 Apr 2012, 3:31 PM
There is always the option of creating a dynamic model from meta, but if this works for you, it seems fine.