Correctly Formatting Sortable Percentages
Starting with the code in the following topic, I tried to add percentage formatting (my modified code is below): /datagrid.8193/sorting-numbers.html
I know that I can manually format the data from the js-array before placing in the grid, but then sorting does not work.
There is another support topic that addresses this problem when loading from XML by applying the formatting to the 'xml table', but I am loading from a js-array.
Note that the code below does sort correctly because of the explicit setting of the column's cell format to AW.Formats.Number. However, the format string ("#,###.00%") does not correctly format the data. I did try variations on the format string to no avail.
Do you have any suggestions? Any help would be appreciated.
My (non-working) modifications are here:
var data = [ ["xxx", "40000.02"], ["yyy", "500.042"], ["zzz", "10.283"] ] var obj = new AW.UI.Grid; obj.setCellText(data); obj.setColumnCount(2); obj.setRowCount(3); var number = new AW.Formats.Number; number.setTextFormat("#,###.00%"); obj.setCellFormat(number, 1); document.write(obj);
In previous posts, Alex has said that better performance would be obtained by applying the mask on the server and sending the data to the client in a "ready to display" format. I can do the server-side formatting, but how (in V2.0) can I also get the column to sort as a numeric, not as a string (given that a mask has been applied).
Numeric masks that I need to use include the following "#,###.00%", "#,###.00", "$ #,###.00"
I started with the following topics; the first works with XML data and the second only tells sorting that the column is numeric, but does not apply a numeric mask. I really need to produce a combination of the two. The last topic addresses the problem for V1.0.
"Data Type Formatting" at /datagrid.8223/data-type-formatting.html shows formatting using XML Data Island
"Sorting Numbers" at /datagrid.8193/sorting-numbers.html shows making js-array data numeric (and sortable), but does us a numeric format mask
I wonder if you made any progress solving your formatting issues? The lack of responses to your post suggest this isn't necessarily trivial.
I, too, have grid data loaded from js array and have run into the issue that applying a mask to a number object e.g.
var money = new AW.Formats.Number; money.setTextFormat("Â£##,###.##");
seems to correctly put the data into the grid as a number (i.e. that is sortable numerically), but without the mask.
Any ideas on this much appreciated.
Try adding a space between the money symbol and the #.
var money = new AW.Formats.Number; money.setTextFormat("Â£ ##,###.##");
Thanks for that suggestion, but I can't get it to work. Have you succeeded with js array data?
This topic is archived.
Back to support forum
Version 2Looking for AW 2.6 ?
The old site is here.