Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Faisal Yahya on Feb 19, 2008 20:02
open dhtmlx forum
Number Format and Sorting

Hi...

I have a problem with displaying the number formatted (using thousand and decimal separator). Number format is not working! I am doing formatting via XML. this is an example of my codding.

<rows>
    <head>
        <beforeInit>
            <call command="groupBy"><param>0</param></call>
        </beforeInit>
        <afterInit>
            <call command="setColumnHidden"><param>0</param><param>true</param></call>
            <call command="setColumnHidden"><param>1</param><param>true</param></call>
            <call command="setNumberFormat">
                <param>0,000</param>
                <param>6</param>
            </call>
        </afterInit>
        <column width='60' align='left' type='ro' sort='str' color='ececec' id='c0'>Company</column>
        <column width='60' align='left' type='ro' sort='str' color='ececec' id='c1'>Risk</column>
        <column width='60' align='center' type='ro' sort='str' color='' id='c2'>Claim No</column>
        <column width='60' align='left' type='ro' sort='date' color='' id='c3'>Date of Loss</column>
        <column width='*' align='left' type='ro' sort='str' color='' id='c4'>Remarks</column>
        <column width='30' align='center' type='ro' sort='str' color='' id='c3'>Curr</column>
        <column width='80' align='right' type='ron' sort='int' color='' id='c5'>Claim Amount</column>
        <column width='80' align='right' type='ron' sort='int' color='' id='c6'>Deductible</column>
        <column width='80' align='right' type='ron' sort='int' color='' id='c6'>Paid</column>
        <column width='80' align='right' type='ron' sort='int' color='FFFFCC' id='c6'>OutStanding</column>
        <column width='2' align='left' type='ro' sort='str' color='' id='c6'>Policy Year</column>
    </head>
...

I also want to sort the date, but not working too. Is there anything that I missed?


TIA,

FY
Answer posted by Support on Feb 20, 2008 06:39
Actually the XML which you provided - works fine, it output 12345 as 12,345
Instead of
    <call command="setNumberFormat">
you can use
      <column width='80' format="0,000.00" align='right' type='ron' sort='int' color='' id='c5'>Claim Amount</column>
Answer posted by Faisal Yahya on Feb 20, 2008 17:12

sorry, but when I run this script. Why it is display 'N.aN' in the column instead of the value?

 

FY

Answer posted by Support on Feb 21, 2008 10:33
The data which you provided as cell value is not a number, grid uses parseFloat function against incoming data to convert it to correct numbers, if incoming data can't be converted to number ( most common issue - it has some extra text chars, such as currency mark ) - data outputed as NaN
Answer posted on Feb 25, 2008 19:55
thanks for the number sorting, now my problem is solved. but I need a help with date sorting, too.

the problem is I have 2 date field, if I sort field 1 the sorting process was working. but if I sort column 2, it still sort the column 1. can we have more than 1 date field on the grid and how to sort it. below is the copy of my code.

<rows>
    <head>
        <beforeInit>
            <call command="groupBy"><param>0</param></call>
        </beforeInit>
        <afterInit>
            <call command="setColumnHidden"><param>0</param><param>true</param></call>
            <call command="setColumnHidden"><param>1</param><param>true</param></call>
        </afterInit>
        <column width='60' align='left' type='ro' sort='str' color='ececec' id='c0'>Company</column>
        <column width='60' align='left' type='ro' sort='str' color='ececec' id='c1'>Risk</column>
        <column width='60' align='center' type='ro' sort='str' color='' id='c2'>Claim No</column>
        <column width='60' align='left' type='ro' color='' id='c3'>Date of Loss</column>
        <column width='60' align='left' type='ro' color='FFFFCC' id='c4'>Progress Date</column>
        <column width='120' align='center' type='ro' sort='str' color='' id='c5'>Progress Status</column>
        <column width='*' align='left' type='ro' sort='str' color='' id='c6'>Description</column>
        <column width='2' align='left' type='ro' sort='str' color='' id='c6'>Policy Year</column>
    </head>

....
</rows>

TIA,

FY
Answer posted by Support on Feb 26, 2008 04:13
Problem may be caused by date format
Currently you not using "sort" attribute at all, which results in sorting dates as strings ( which most probably is incorrect )
If you specify sort="date" - it will sort dates correctly, but only if they are in default format => mm/dd/yyyy

If you are using data in any other format - you need to specify custom sorting routine for such columns

    http://dhtmlx.com/docs/products/kb/index.shtml?cat=search&q=1897&ssr=yes&s=sort%20date