3.2.0

Sort GRID Items based onthe Header Name

Hello Support Team,

I am using a Active Widgets GRID and I want to set the sort Format of the column based on the header name.

i.e., If the Header Name is "Date" then the "AW.Formats.Number" must be set dynamically after building the GRID.

If the case is with the static columns then that is working fine, and I'm able to set the sort format of the columns.

I've a requirement where the columns will be generated dynamically and the grid will reload / change the columns when we click on a button on that page. So, how to set the sort format in this case.

I'm Using C#.Net for generating the columns and building the GRID dynamically. - This is FYI

Thank you very much for your help In advance.
Uday
December 3,
Assuming that your headers are set dynamically (and that the C# prints out into a javascript array), simply analyze the header array and set the formats for those columns based on their names.

I think something like this should work...
//Javascript
myHeaders = ["Date","Number","Text","Date"]; //This is set dynamically
myGrid.setHeaderText(myHeaders);

//Prepare the formats that the columns will be assigned
var dateFormat = new AW.Formats.Date;
    dateFormat.setDataFormat("ISO8601"); //date format from the db
    dateFormat.setTextFormat("yyyy-mm-dd"); //date format to display
var numbFormat = new AW.Formats.Number;
    numbFormat.setErrorText(""); //suppress empty/non-numeric values
    numbFormat.setErrorValue(0); 
var textFormat = new AW.Formats.String;

var headerLen = myHeaders.length;
for(var i = 0;i<headerLen;i++){
    var curFormat = "";
    switch(myHeaders[i]){
        case "Date":
            curFormat = dateFormat;
            break;
        case "Number":
            curFormat = numbFormat;
            break;
        default:
            curFormat = textFormat;
    }
    myGrid.setCellFormat(curFormat,i);
}


Also, you should look at the format AW.Formats.Date for your date columns. It's very useful for working with dates, as you can store dates in the database and then display them differently without having to mess with converting them between formats yourself.
JohnW
December 4,

This topic is archived.

See also:


Back to support forum