PDA

View Full Version : How to create a Record with dynamic fields



rahulmca1@gmail.com
10 Aug 2007, 7:17 AM
Hi,
I need to create a Ext.data.Record from the following xml to update a row in an existing grid.


<row>
<column id="1" value="one" />
<column id="2" value="two" />
<column id="3" value="three" />
</row>


The "<row>" node represents a record, the "id" the column id and the "name" the value for that column.
The Record constructor expects data in form of "An associative Array of data values keyed by the field name."
In my case however these keys are dynamic and need to be extracted from the xml (the "id" attribute), so how do i create an Object to pass to the Record constructor.
Thanks a lot.

RWaters
10 Aug 2007, 9:22 AM
If you're looking to update an existing grid, couldn't you just get ahold of that existing Ext.data.Record?



var grid = new Ext.grid.Grid({ blah blah blah });
var row = grid.getDataSource().getById('rowid');
// loop through column records
row.set('column id', 'column value')

matjaz
10 Aug 2007, 10:24 AM
With a simple Ext.Ajax class request XML and inside of callback you use DomQuery and a code similar what RWaters wrote and that's about it. :)

rahulmca1@gmail.com
10 Aug 2007, 9:35 PM
Hi,
That solves the updation of a row, but how do i add a new row.
The XML provies the "columnId" as well as the "column-values".
I cannot understand how to create a new Record which requires "An associative Array of data values keyed by the field name.", when my keys are dynamic.
Thanks a lot.

genius551v
11 Aug 2007, 6:09 AM
I cannot understand how to create a new Record which requires "An associative Array of data values keyed by the field name.", when my keys are dynamic.

rahulmca1@gmail.com, maybe this can help you...


function addRow(){
grid.stopEditing();
var config = [];
for(var x in ds.fields.keys) {
var y = ds.fields.keys[x];
if(ds.newRecord.hasOwnProperty(y)){
config[ds.fields.keys[x]] = ds.newRecord[y];
}else{
config[ds.fields.keys[x]] = '';
}
}
config['newReg'] = true;
var newRow = new ds.reader.recordType(config);
ds.add(newRow);
};


i not sure, i just testing that, let me know your advance :-?