3.2.0

setXML() again and XML


I have a table I'm populating with an external SOAP call outside of AW and trying to get the changes in the grid written back to that XML. I've seen the table.setText solution for that multiple times in the forums and tried this:

var table = new AW.XML.Table;
var obj = new AW.UI.Grid;

obj.setId("myGrid");

table.setText = function(value, i, j){
var node = this.getNode(i, j);
node.text = value; }
table.setXML(myXMLObject.xml);

obj.setCellModel(table);
obj.setColumnCount(7);
obj.setRowCount(myXMLObject.childNodes.length);
document.write(obj);

I get errors at runtime that say there's an error on the
line of the table.setText - if I put some alert()'s in
I find that value, i, and j inside the function are
being called with all three equal 'null'. Is this another
case where the table.request() has done something
to set up the table and table.setXML() is left without
that?

I'm almost thinking at this point the whole approach of
the table.setText is wrong anyway - no matter how
often it's thrown about here. Why shouldn't the grid's
on value change of the cell go off to the XML node and
modify that? Change the grid, change the XML that's
what the tie should be.

Geoff
March 13,
table.setText() is definitely wrong to me. The grid content typically comes through three phases -

1). external source (either external AW.XML.Table or cell data property). This is how the data comes from the server, which might be some internal format, different from javascript representation and different from what the end user sees on screen.

2). internal values (cell value property). This is grid internal storage in javascript native format - String, Number, Date etc. Used for sorting.

3). formatted display text (cell text property). This is what goes into the cell html for the end user display.

The editing process in theory should go in reverse order. When the user types something in the cell - the cell editor immediately (on each keypress, copy/paste/del) sends the modified text into the cell text property, so you can monitor what is going on inside the editor and validate/change on the fly if necessary.

When the cell is validated the cell text is parsed and sent to cell value property, and the cell format is applied back to produce new cell text.

Now, in some scenarios you may want to send the value immediately back to the data source (i.e. table.setData). In other cases you may want to wait until the user edits other cells, validate the whole row and only then send it to the source. There is also a possibility that the rows should be updated not one-by-one but all modified rows in the single batch update (?).

Currently the grid implements only the first step - pass the edited text back to the cell text property. To complete this you should implement at least two things -

1). using onCellValidated event parse the cell text and store the result in cell value (or directly in cell data) property.

// after validation update 'data' and remove 'text' properties
obj.onCellValidated = function(text, col, row){
    var format = this.getCellFormat(col, row);
    var data = format ? format.textToData(text): text;
    this.setCellData(data, col, row);
    this.setCellText(undefined, col, row); // remove edited text
}


2). implement table.setData method

table.setData = function(value, col, row){
    var node = this.getNode(col, row);
    if (AW.ie) {
        node.text = value;
    }
    else {
        node.textContent = value;
    }
}


I will try to finish all these steps in the next release. I would very much appreciate any suggestions related to editing sequence or any good implementation examples.
Alex (ActiveWidgets)
March 13,
I ended up doing almost exactly that in my own code, just manually. The only issues is that my node saving is perfect, I can go to the right node, store its value and all is well there.

But I seem to be having a problem with the format being applied the way I need. If the value is plain text, all is well. But my biggest issue is a date value. The display value is mm/dd/yyyy which is fine, but the XML has to be in the ISO format - which you do support translation. No matter what I do with getCellFormat and textToData, I can't get back to yyyy-mm-dd which is the ISO format the back end expects.

Another interesting note - the code above for setCellData and setCellText ends up giving me blank visible in the grid, and the mm/dd/yyyy in the getCellData.
Geoff
March 15,

This topic is archived.

See also:


Back to support forum