Setting Format of some column to AW.Formats.Number on xml based grid do not format the cell data in those columns
Hi Alex
I am trying to set the format of a column to AW.Formats.Number and formatting the data with the following :
var cellFormatter2 = new AW.Formats.Number;
cellFormatter2.setTextFormat("###,###,###,###");
obj.setCellFormat(cellFormatter2,1);
This I am doing for second column. and using xml Model to receive data from remote server that exports data as xml stream.
I am not able to see my data formatted as 222,223,445,666
Can u help me out to resolve this issue.
Thanks
Vikramaditya Garg
Vikramaditya Garg
August 3,
The format should be "#,###." for zero decimals
var cellFormatter2 = new AW.Formats.Number;
cellFormatter2.setTextFormat("#,###.");
obj.setCellFormat(cellFormatter2,1);
Alex (ActiveWidgets)
August 3,
Hi Alex
I really appreciate your response.
Everything seems to be fine.Now after applying the formatting and making those cells uneditable , we are trying to sort the data for that particular column but the sorting breaks now.
I have tried to set the text in on cell using onCellEditStarted event and reapplied the formatting on onCellEditEnded event but the sorting still breaks.
I have found that If I change column "Employees" with values 10 100 and 12 and then do sorting ...it breaks.. but if i edit three cells of employee and give values as 010 100 012 .The sorting runs perfectly fine.It seems that there is some inconsistency between text,data,value
I am attaching you the sample code .Please help us to resolve the issue.
/********** Code starts Here ***************/
<html>
<head>
<title>ActiveWidgets Grid :: Edit And Sort</title>
<style> body, html {margin:0px; padding: 0px; overflow: hidden;} </style>
<!-- ActiveWidgets stylesheet and scripts -->
<link href="runtime/styles/xp/aw.css" rel="stylesheet" type="text/css" ></link>
<script src="runtime/lib/aw.js"></script>
<!-- grid format -->
<style>
.aw-grid-control {height: 100%; width: 100%; margin: 0px; border: none; font: menu;}
.aw-row-selector {text-align: center}
.aw-column-0 {width: 80px;}
.aw-column-1 {width: 200px;}
.aw-column-2 {text-align: right;}
.aw-column-3 {text-align: right;}
.aw-column-4 {text-align: right;}
.aw-grid-cell {border-right: 1px solid threedlightshadow;}
.aw-grid-row {border-bottom: 1px solid threedlightshadow;}
</style>
<!-- grid data -->
<script>
var myColumns = [
"Ticker", "Company Name", "Market Cap.", "$ Sales", "Employees"
];
</script>
</head>
<body>
<script>
// create ActiveWidgets data model - XML-based table
var table = new AW.XML.Table;
// provide data URL
table.setURL("companies-simple.xml");
// start asyncronous data retrieval
table.request();
table.setData = function(value, col, row){
//alert("here");
var node = this.getNode(col, row);
if (AW.ie) {
node.text = value;
}
else {
node.textContent = value;
}
}
// create ActiveWidgets Grid javascript object
var obj = new AW.UI.Grid;
// define data formats
var str = new AW.Formats.String;
var num = new AW.Formats.Number;
//num.setTextFormat("#,###.");
var floatFormat = new AW.Formats.Number;
floatFormat.setTextFormat("#,###.###");
obj.setCellFormat([str, str, floatFormat, floatFormat,num]);
// provide cells and headers text
//obj.setCellText(myData);
obj.setHeaderText(myColumns);
// set number of rows/columns
obj.setRowCount(20);
obj.setColumnCount(5);
// enable row selectors
obj.setSelectorVisible(true);
obj.setSelectorText(function(i){return this.getRowPosition(i)+1});
// set headers width/height
obj.setSelectorWidth(28);
obj.setHeaderHeight(20);
// set row selection
obj.setSelectionMode("single-cell");
obj.setCellEditable(true);
// set click action handler
obj.onCellClicked = function(event, col, row){window.status = this.getCellText(col, row)};
// assign external 'data model'
obj.setCellModel(table);
// write grid html to the page
document.write(obj);
obj.onCellEditStarted = function(text, col, row){
//alert(obj.getCellText(col,row));
obj.setCellText(obj.getCellValue(col,row),col,row);
}
obj.onCellEditEnded = function(text, col, row){
alert(text);
obj.setCellValue(text,col,row);
alert(obj.getCellValue(col,row));
obj.setCellData(text,col,row);
//alert("data :" + obj.getCellData(col,row));
//alert("con text :" + this.getCellFormat(col, row).dataToText(text));
obj.setCellText(this.getCellFormat(col, row).dataToText(text),col,row);
//alert(obj.getCellText(col,row));
}
obj.onKeyCtrlC = function(event){
var c = this.getCurrentColumn();
var r = this.getCurrentRow();
//copyToClipBoard(removeCommas(this.getCellText(c, r)));
copyToClipBoard("Text : " + this.getCellText(c, r) + " Data : " + this.getCellData(c, r) + " Value : " + this.getCellValue(c, r));
AW.setReturnValue(event, false); // prevent default
}
/****** Copies text to system clipboard *****/
function copyToClipBoard(text) {
if (window.clipboardData) {
// the IE-manier
window.clipboardData.setData("Text", text);
}
return false;
}
</script>
</body>
</html>
/********** Code ends Here ***************/
The contents of companies-simple.xml are
<companies>
<company>
<ticker>MSFT</ticker>
<name>Microsoft Corporation</name>
<mktcap>314571.1564</mktcap>
<sales>32187.000</sales>
<employees>544445</employees>
</company>
<company>
<ticker>ORCL</ticker>
<name>Oracle Corporation</name>
<mktcap>62615.26</mktcap>
<sales>9519.02</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>
<company>
<ticker>CA</ticker>
<name>Computer Associates Inter</name>
<mktcap>15606.335</mktcap>
<sales>3164.000</sales>
<employees>16000</employees>
</company>
<company>
<ticker>ERTS</ticker>
<name>Electronic Arts Inc.</name>
<mktcap>14490.895</mktcap>
<sales>2503.727</sales>
<employees>4000</employees>
</company>
<company>
<ticker>SFTBF</ticker>
<name>Softbank Corp. (ADR)</name>
<mktcap>14485.840</mktcap>
<sales>.000</sales>
<employees>6865</employees>
</company>
<company>
<ticker>VRTS</ticker>
<name>Veritas Software Corp.</name>
<mktcap>14444.272</mktcap>
<sales>1578.658</sales>
<employees>5647</employees>
</company>
<company>
<ticker>SYMC</ticker>
<name>Symantec Corporation</name>
<mktcap>9932.483</mktcap>
<sales>1482.029</sales>
<employees>4300</employees>
</company>
<company>
<ticker>INFY</ticker>
<name>Infosys Technologies Ltd.</name>
<mktcap>9763.851</mktcap>
<sales>830.748</sales>
<employees>15400</employees>
</company>
<company>
<ticker>INTU</ticker>
<name>Intuit Inc.</name>
<mktcap>9702.477</mktcap>
<sales>1650.743</sales>
<employees>6700</employees>
</company>
<company>
<ticker>ADBE</ticker>
<name>Adobe Systems Incorporate</name>
<mktcap>9533.050</mktcap>
<sales>1230.817</sales>
<employees>3341</employees>
</company>
<company>
<ticker>PSFT</ticker>
<name>PeopleSoft, Inc.</name>
<mktcap>8246.467</mktcap>
<sales>1941.167</sales>
<employees>8180</employees>
</company>
<company>
<ticker>SEBL</ticker>
<name>Siebel Systems, Inc.</name>
<mktcap>5434.649</mktcap>
<sales>1417.952</sales>
<employees>5909</employees>
</company>
<company>
<ticker>BEAS</ticker>
<name>BEA Systems, Inc.</name>
<mktcap>5111.813</mktcap>
<sales>965.694</sales>
<employees>3063</employees>
</company>
<company>
<ticker>SNPS</ticker>
<name>Synopsys, Inc.</name>
<mktcap>4482.535</mktcap>
<sales>1169.786</sales>
<employees>4254</employees>
</company>
<company>
<ticker>CHKP</ticker>
<name>Check Point Software Tech</name>
<mktcap>4396.853</mktcap>
<sales>424.769</sales>
<employees>1203</employees>
</company>
<company>
<ticker>MERQ</ticker>
<name>Mercury Interactive Corp.</name>
<mktcap>4325.488</mktcap>
<sales>444.063</sales>
<employees>1822</employees>
</company>
<company>
<ticker>DOX</ticker>
<name>Amdocs Limited</name>
<mktcap>4288.017</mktcap>
<sales>1427.088</sales>
<employees>9400</employees>
</company>
<company>
<ticker>CTXS</ticker>
<name>Citrix Systems, Inc.</name>
<mktcap>3946.485</mktcap>
<sales>554.222</sales>
<employees>1670</employees>
</company>
<company>
<ticker>KNM</ticker>
<name>Konami Corporation (ADR)</name>
<mktcap>3710.784</mktcap>
<sales>.000</sales>
<employees>4313</employees>
</company>
</companies>
Vikramaditya Garg
August 11,
This issue occurs with editable cells.
Thanks
Vikramaditya Garg
Vikramaditya Garg
August 11,
the response is still awaited...
Please some help us as the problem is critical to us
Thanks
Vikramaditya Garg
Vikramaditya Garg
August 13,