PDA

View Full Version : Grid: adding fields to XMLDataModel onLoad



carsten
18 Oct 2006, 7:56 AM
Hi there,

first of all: thx a lot to Jack for all this awesome good work!!

Jack, or anybody else: could U provide me with ideas / recommendation on how to - on the client side - add fields when XML data has finished loading?

An example case: from the server I receive values for eg. loginCount and purchaseCount and have these 2 be shown as cols - now IŽd like to add a 3rd column to display the 'login to purchase' percentage there.

How do I do similar the best way? Add a preprocessor to create a new node or similar?

Thx for any idea!
carsten

jack.slocum
18 Oct 2006, 10:13 AM
Personally, I would do that at the source of the document. If you have to do it client-side, you could do it by overriding insertRows (and addRows if you use it manually, but internally the grid uses insertRows when loading the XML). You could try something like this, assuming your data model was called dataModel:

1. Define a bogus column in your XMLDataModel schema that won't match any nodes.

2. Override insertRows:


dataModel.insertRows = function(index, data){
//data would be a multi-dimensional array of rows and column data.
// loop through each row and set our bogus column (column 5) value
// to the sum of column 2 and 4
for(var i = 0, len = data.length; i < len; i++){
var colData = data[i];
colData[5] = colData[2] + colData[4];
}
// call the default insertRows
YAHOO.ext.grid.XMLDataModel.prototype.insertRows.call(this, index, data);
};


It would useful to add this functionality built in though. I can see where it would definitely be useful. I will look at adding it in a future release.