3.2.0

Data Handling Question

I am attaching an XML table to a grid. My table only has 4 columns. I'd like to be able to add more columns in the grid based on values of the table. Currently the only way I have figured out how to do this is replicate the same column twice and then change the cellFormat to my own custom creation that does what I want.

var string = new AW.Formats.String;

var uxdate = new AW.Formats.Date; 
uxdate.setTextFormat("mmmm dd, yyyy hh:mm:ss"); 
uxdate.dataToValue = function(d){return Number(d)*1000}; 		
uxdate.setErrorText("");
uxdate.setErrorValue(0);

var customdate= new AW.Formats.Number; 
customdate.dataToText = function(d,i){
            if (Number(d) < 1){
                return "<a href=\"#\">not set</a>";
            } else {
                return "";
            }
        };

var table= new AW.XML.Table;
table.setURL("data.xml");
table.setRows("//data_feed/*");
table.setColumns(["col1", "col2", "col3", "col4", "col4"]);
table.request();

var columns = ["Col1", "Col2", "Col3", "Col4", "Col5"];
var grid= new AW.UI.Grid;
grid.setId("grid");
grid.setColumnCount(5);
grid.setHeaderText(columns);
grid.setSelectorVisible(false);
grid.setSelectionMode("single-row");
grid.setCellFormat([string, string, uxdate, uxdate, customdate]);
grid.setCellModel(table);
grid.refresh();


In the above example, I have 2 columns (4 & 5) with the same data...one to show the data and another to show a link if the data equals a certain value. If my link is shown and I click on it I would like to fire another function but pass the data from the first column (1).

I hope I have described this so someone can help. I really appreciate anything anyone can offer here.
AT
November 9,
You can set columnCount to a larger number than your actual columns in the data source and assign a function directly to the cellText property of the additional columns. You just have to do it after the call to setCellModel(table) -

// ...
obj.setCellModel(table);

function calc(col, row){
    return this.getCellText(0, row) + ' ' + this.getCellText(1, row);
}

obj.setCellText(calc, 4);
Alex (ActiveWidgets)
November 10,
Alex,

Worked great! Thanks!
AT
November 11,
Alex,

On a side note...the code you provided worked great to add additional columns to after the columns already there from my table. But is there any way to insert a column in the middle of the existing columns created by setCellModel(table)?

Thanks
AT
November 11,
You can change column order (or hide/show columns) with setColumnIndices([...]) method -

obj.setColumnIndices([4,0,1,2,3]);
Alex (ActiveWidgets)
November 11,

This topic is archived.

See also:


Back to support forum