Search code examples
extjsgridstore

dynamic store in column grid editable


In a grid column editable (ExtJs v4.2.2), how to change the store dynamically ? The point is to load store with different params by type of movement(movementTypeId):

the field with diffrent list to be attached is 'Reason', columns are:

this.columns = [
{
    text: 'id',
    dataIndex: 'movementId',
    sortable: false,
    hideable: true,
    sortableColumn: false,
    hidden: true,
    flex : 1,
    scope:this
},
{
    text: 'TypeId',
    dataIndex: 'movementTypeId',
    sortable: false,
    sortableColumn: false,
    hideable: true,
    sortableColumns: false,
    hidden: true,
    flex : 2,
    scope:this
},

{
    text: 'Reason',
    dataIndex: 'movementReasonId',
    sortable: false,
    hideable: true,
    sortableColumn: false,
    field: {
        xtype: 'combobox',
        align: 'center',
        typeAhead: true,
        triggerAction: 'all',
        //selectOnTab: true,
        store: this.storeMovementReasonType,
        displayField: 'label'
    },
    flex : 3,
    scope:this
},

];

So for every row, when store is on load wanted to set extra param like:

if(movementTypeId === 89){
 storeMovementReasonType.getProxy().setExtraParam('dictionaryTypeId',11);
 }
 if(movementTypeId === 94){
    storeMovementReasonType.getProxy().setExtraParam('dictionaryTypeId',8);
 }

is it possible ? Thanks for your time :)


Solution

  • You want to implement the beforeedit listener on your rowediting plugin:

    listeners:{
        beforeedit:function(editor , context , eOpts) {
            var movementTypeId = context.record.get("movementTypeId");
            if(movementTypeId === 89){
                storeMovementReasonType.getProxy().setExtraParam('dictionaryTypeId',11);
            }
            if(movementTypeId === 94){
                storeMovementReasonType.getProxy().setExtraParam('dictionaryTypeId',8);
            }
            storeMovementReasonType.load();
        }
    }