I am developing an application using ExtJS, and in one of my models I have field which is an array type, how can I set a dataIndex in grid so the data does not repeat when I edit one cell?
My code is shown below.

{
xtype: 'button',
icon : Webapp.icon('add1.png'),
iconAlign : 'top',
handler : function() {
var gridView = Ext.ComponentQuery.query('gridpanel')[1];
grid = gridView.headerCt;
if(grid.getGridColumns().length >= 1){
var column = Ext.create('Ext.grid.column.Column', { dataIndex: 'interval', text : contador,
editor: {xtype: 'textfield', flex: 0.5, editable: true}});
grid.insert(gridView.columns.length, column);
gridView.getView().refresh();
var botao = Ext.getCmp('buttonRemoverColuna');
botao.setDisabled(false);
}
contador++;
}
}
Ext.define('model', {
extend : 'Ext.data.Model',
fields : [ {
name : 'id',
type : 'long'
}, {
name : 'name',
type : 'string'
}, {
name: 'interval',
type: 'array'
}]
});
The simple answer is that you have to give each new column that you insert a different
dataIndexconfig.Right now every one gets
dataIndex: 'interval'.That means if you put a value in the
intervalfield in your store for that record, every single column that is connected to theintervalfield will show up with that value.A simple way to do that would be to change the handler to this:
Specifically, the following config from the handler will give it an incremented
dataIndex, i.e.interval1,interval2,interval3,interval4, etc. I don’t know anything about your server side set-up so I don’t know if it will work for you:EDIT:
Assuming you are not defining a custom
arraydata type, yourintervalfield data type will actually default tostring. It will be easy to accomplish what you want using the grid column’srendererconfig, I’ll post an example in a moment but you may as well change the data type back tostring.EXAMPLE:
The basic idea is to add a renderer to the column config that will show the individual
intervalvalues in the added columns by splitting the realintervalfield value into an array. You will still need an implementation of the grid columns with seperatedataIndexconfigs as shown above so that we can identify what columns match up to whatintervalarray value.You will also need
beforeeditandeditevent listeners on the grid.The
beforeedithandler will split theintervalvalues into the correct column fields when you start a row edit.The
edithandler will join the updated field values from the different columns into a single string and apply it to the realintervalfield when you complete a row edit.With the above
editlistener, the value of your model’sintervalfield will be updated with the values in your added columns as a CSV string e.g.:'value1,value2,value3,etc'.Parsing the string on your server side is up to you. But in most programming language there is a
stringValue.split(",")type of function which will convert the CSV string into a real array.If you wanted the
intervalvalue to be more “array-like” you could also wrap it in brackets:I don’t know if that would help your parsing or not.