PDA

View Full Version : AddRow in a grid when the xml don't have data



franklt69
22 Feb 2007, 8:20 AM
Hi I have a grid it load data from a xml.
The xml is generated in the server based in a search, when there is data the grid show its, if I add a row it work ok

gridAddress.getDataModel().addRow(1,['a1','a1','a2','c','country','county','pc','fl','5555','home','10:181']);

the new row appear in the grid, but when I do a search and the xml don't have data the grid appear empty again is ok, then when I do it:

gridAddress.getDataModel().addRow(1,['a1','a1','a2','c','country','county','pc','fl','5555','home','10:181']);

I get this error:
this.data[0] has no properties

in yui-ext-debug.js
createNode: function(xmlDoc, id, colData){
var template = this.data[0].node;
var newNode = template.cloneNode(true);
var fields = this.schema.fields;
for(var i = 0, len = fields.length; i < len; i++){

the xml response from server is
<?xml version="1.0" encoding="Windows-1252"?><xmlResponse><TotalCount>0</TotalCount></xmlResponse>

so the question how I can add a row when I don't have data in the xml?

if I send the xml with data empty the grid will show it (how a record empty) and I don't want it
is there solution?

kind regards
Frank

tryanDLS
22 Feb 2007, 8:41 AM
When there are no rows, you haven't passed back an XML node to be used as the basis of the add (clone). I would think you probably would need to pass back a dummy XML element with all child nodes as empty. This should give you a blank row in the grid initially, so you'd have to add some handling for that e.g. don't allow it to be selected, remove it upon the 1st add, etc.
Or, you could keep that empty XML element in a var someplace and use it as a template for creation. Override createNode with logic that follows the normal flow, but uses your XML template in the case were there is no data. That way, you don't have to handle special cases for selection of a blank row

franklt69
22 Feb 2007, 10:16 AM
Ok thanks a doubt I wil have to do the same when the xml is empty in the 1.0 version?

is stable operation like inline edit the grid in the 1.0 version today?

kind regards
Frank