:: Forum >>

Data Type Formatting

Is there a way to format columns by applying a mask or some type of formatting?
I would like to tell the grid to display column x as currency, column y as vbShortDate etc...

Is this ability built into the grid??

If not, does anybody have any ideas on what may be the easist way to implement something like this??


I realize I can format the data before I pass it to the grid, but I am using an XML Data Island from a recordset, and I never actually loop through the data.

I have also been trying to find an xsl solution to this problem, but can't seem to find an example or tutorial that explains how to format data by data type, or even how to determine the data type for a given value.
Jim Shaffer
Monday, October 24, 2005
Jim,

it is possible to format your XML data inside AW.XML.Table class. For this purpose you should create formatting objects (instances of AW.Formats.Number/Date/String class), configure them and assign to table column.

Here is complete formatting example:

<html>
<head>
    <link href="../../runtime/styles/xp/aw.css" rel="stylesheet" type="text/css" ></link>
    <script src="../../runtime/lib/aw.js"></script>
    <style>
        .aw-grid-control {height: 150px; width: 100%; font: menu;}
    
</style>
</head>
<body>
    <xml id="xmlDataIsland">
        <companies>
            <company>
                <ticker>MSFT</ticker>
                <name>Microsoft Corporation</name>
                <mktcap>314571.156</mktcap>
                <sales>32187.000</sales>
                <employees>55000</employees>
            </company>
            <company>
                <ticker>ORCL</ticker>
                <name>Oracle Corporation</name>
                <mktcap>62615.266</mktcap>
                <sales>9519.000</sales>
                <employees>40650</employees>
            </company>
            <company>
                <ticker>SAP</ticker>
                <name>SAP AG (ADR)</name>
                <mktcap>40986.328</mktcap>
                <sales>8296.420</sales>
                <employees>28961</employees>
            </company>
        </companies>
    </xml>
    <script>

    // create ActiveWidgets data model - XML-based table
    var table = new AW.XML.Table;

    // fix for format index bug in 2.0b1
    table.getText = function(i, j){
        var node = this.getNode(i, j);
        var data = node ? node.text : "";
        var format = this._formats[i];
        return format ? format.dataToText(data) : data;
    };

    // create formatting object
    var number = new AW.Formats.Number;

    // configure formatting object
    number.setTextFormat("$ #,###.#");

    // assign format to data column
    table.setFormat(number, 2);


    // get reference to the xml data island node (IE only)
    var xml = document.getElementById("xmlDataIsland");

    // provide data XML
    table.setXML(xml);

    // define column labels
    var columns = ["Ticker", "Company Name", "Market Cap.", "$ Sales", "Employees"];

    // create ActiveWidgets Grid javascript object
    var obj = new AW.UI.Grid;

    // set number of rows, columns
    obj.setColumnCount(5);
    obj.setRowCount(3);

    // provide column labels
    obj.setHeaderText(columns);

    // provide external model as a grid data source
    obj.setCellModel(table);

    // write grid html to the page
    document.write(obj);

    
</script>
</body>
</html>


More formatting samples are here:

http://www.activewidgets.com/javascript.forum.8116.0/example-using-recordset-xml-output.html
Alex (ActiveWidgets)
Monday, October 24, 2005

This topic is archived.


Back to support forum

Forum search