PDA

View Full Version : [ExtJs4.1] Grid FilterFeature not filtering Associated Models



dwr
19 Jul 2012, 6:51 AM
I try to use associated models with grid filter feature.

associated models load (good).
Grid loads also (good)
Grid loads filtered data matching parent model id (good).

On the loaded grid trying to use usual filtersfeature for filtering within already filtered model.

e.g.
MyModel1 - 1 record id 1000.
MyModel2 - 100 records which match id 1000.
MyMymode2.ModelId = MyModel1.Id (or ModelId aliased for ease).

so now from MyModel2 want to show only records which match Name = "SomeName" using remote filtering.

Request being sent to remote on MyModel2 load includes only MyModelId and ignores Filter for Name column.

Here is an example structure ported from my real app.




Ext.define('MyApp.model.MyModel1', {
extend: 'Ext.data.Model',
hasMany: [{
model: 'MyApp.model.MyModel2',
name: 'SubModel',
primaryKey: 'Id',
foreignKey: 'ModelId',
filterProperty: 'ModelId',
autoLoad: true
}],
idProperty: 'Id',
fields: [{
name: 'Id'
}, {
name: 'ModelId',
mapping: 'Id'
}, {
name: 'Field1'
}, {
name: 'Field2'
}]
});

Ext.define('MyApp.model.MyModel2', {
extend: 'Ext.data.Model',
belongsTo: {
model: 'MyApp.model.MyModel1',
primaryKey: 'Id',
foreignKey: 'MyModelId',
autoLoad: true
},
idProperty: 'Id',
fields: [{
name: 'Id'
}, {
name: 'MyModelId'
}, {
name: 'Name'
}, {
name: 'Status'
}]
});

Ext.define('MyApp.view.Edit', {
extend: 'Ext.window.Window',

initComponent: function() {
var me = this;

Ext.applyIf(me, {
items: [{
id: 'MyGrid',
xtype: 'gridpanel',
store: 'MyModel2',
features: [{
ftype: 'filters',
autoReload: true,
local: false
}],
columns: [{
xtype: 'gridcolumn',
width: 50,
dataIndex: 'Id',
text: 'Id'
}, {
xtype: 'gridcolumn',
width: 122,
dataIndex: 'Name',
text: 'Name',
filterable: true
}, {
xtype: 'gridcolumn',
width: 122,
dataIndex: 'Status',
text: 'Name',
filterable: true
}]
})
});

me.callParent(arguments);
}
});


Request Bodies:

Actual Request Body:


{
dataPage:1
start:0
limit:25
filter:[{"property":"ModelId","value":"82"}]
}


Expected Request Body:


{
dataPage:1
start:0
limit:25
filter:[{"property":"ModelId","value":"82"}, {"property":"Name","value":"SomeName"}]
}


or if I set


features: [{
ftype: 'filters',
autoReload: true,
local: false,
paramPrefix: 'myfilter'
}],


then Expected Request Body:


{
dataPage:1
start:0
limit:25
filter:[{"property":"ModelId","value":"82"}],
myfilter[0][field]="Name",
myfilter[0][data][type]="string"&,
myfilter[0][data][value]="SomeName"
}