:: Forum >> Version 2 >>

Correctly Formatting Sortable Percentages

I am trying to correctly format a column of percentages (v2.0b1), with the requirement that they still sort correctly.

Starting with the code in the following topic, I tried to add percentage formatting (my modified code is below): /javascript.forum.8193.2/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(number1); 

    
document.write(obj); 
 
David Parr
Thursday, November 3, 2005
Could any one point me to a solution to the problem below? To clarify/expand on my first note, I am looking for the correct in V2.0b[12] way to apply a numeric mask to js-array data and still allow correct sorting.

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 /javascript.forum.8223.1/data-type-formatting.html shows formatting using XML Data Island

"Sorting Numbers" at /javascript.forum.8193.2/sorting-numbers.html shows making js-array data numeric (and sortable), but does us a numeric format mask

"How to Format the data of JavaScript Array? " at /javascript.forum.788.7/how-to-format-the-data.html shows V1.0 example of client-side formatting
David Parr
Tuesday, November 8, 2005
David

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.

Will
Will
Friday, November 25, 2005
Will,
Try adding a space between the money symbol and the #.

var money = new AW.Formats.Number
money.setTextFormat("£ ##,###.##"); 
 
Rick Villela
Sunday, November 27, 2005
Rick

Thanks for that suggestion, but I can't get it to work. Have you succeeded with js array data?

Will
Will
Monday, November 28, 2005



This topic is archived.

Back to support forum

Forum search