PDA

View Full Version : Add programmatically a new row in a GridStore



pegaso52it
11 Sep 2009, 5:13 AM
Hi all,
I need to add programmatically a row in a GridStore, for do this I have wrote:


...
tbar: [{
text: 'Add Record',
handler : function(){
var defaultData = {
column1: 0,
column2: 'test',
column3: (new Date()).clearTime(),
column4: true
};
var recId = 1;
var p = new store.recordType(defaultData, recId);
grid.stopEditing();
store.insert(0, p); // add new record to the store
grid.startEditing(0, 0);
}
}]
.......
This works perfectly, but I have to put in var defaultData all the data that has my row
(column1, 2, 3, 4)

if I build my defaultData var using:



var defaultData = {
column1: 0
};


The rows is inserted too (on screen I see it) but when I read the grid store for that line
the unique data I have theonly value 0 (the column1 value)

Is there a way to add my row and force the store to use default values (e.g 0 for numbers, false for boolean and so on) for attributes that is not specified?

In my example:
for column 2 ''
for column 3 ''
for column4 false

Thanks

Condor
11 Sep 2009, 5:15 AM
Not unless you program it yourself. Ext will set all field values that are not specified to 'undefined'.

Example:

var defaults = {};
store.fields.each(function(f){
var v;
switch(f.type){
case "string":
v = '';
break;
case "int":
case "integer":
case "float":
v = 0;
break;
case "bool":
case "boolean":
v = false;
break;
default:
v = null;
break;
}
defaults[f.name] = v;
});