Check documentation for the latest version of dhtmlxSuite Formatting Number and Date Values DHTMLX Docs

Formatting Number and Date Values

Numbers

Formatting is applied just to columns(cells) of types ron and edn.


To set format for a number column (or cell) you should use the method setNumberFormat().

The method takes 4 parameters:

  • mask - the numeric mask (e.g. 0,000.00). While specifying the mask you should use the default decimal and group separators ('.' and ',').
  • index - the index of a column the formatting will be applied to;
  • d_sep - (optional) the decimal separator char (by default, '.');
  • g_sep - (optional) the group separator char (by default, ',').

Setting number format for a column

mygrid = new dhtmlXGridObject('gridbox');
mygrid.setColTypes("edn,..");
mygrid.setNumberFormat("0,000.00",0,"'",".");
...
mygrid.init();

Related sample:  Date/Decimal format


Number formats in different countries:

  • USA
mygrid.setNumberFormat("0,000.00",index,".",",");

Example: 1456.789 => 1,456.79

  • UK
mygrid.setNumberFormat("0,000.00",index,",","");

Example: 1456.789 => 1456.79

  • France
mygrid.setNumberFormat("0,000.00",index,","," ");

Example: 1456.789 => 1 456.79

  • Russia
mygrid.setNumberFormat("0,000.00",index,",",".");

Example: 1456.789 => 1.456,79

  • Greece
mygrid.setNumberFormat("0,000.00",index,"."," ");

Example: 1456.789 => 1 456.79

  • Switzerland
mygrid.setNumberFormat("0,000.00",index,".","'");

Example: 1456.789 => 1'456.79


In case of XML configuration you can set format as:

<column type="edn" width="150" sort="str" format="0.00"/>

In case of HTML configuration you can set format as:

<td type="edn" format="0,000.00">Column 3</td>


Decimal and group separators can be set globally as part of grid internationalization, i.e. the specified values will be applied to all columns in the grid automatically and you won't need to specify them through the setNumberFormat() method.

Setting global values for decimal and group separators

mygrid = new dhtmlXGridObject('gridbox');
mygrid.setColTypes("edn,ron,..");
mygrid.i18n.decimal_separator=","
mygrid.i18n.group_separator="'";
mygrid.setNumberFormat("0,000.00",0);//1456.789 => 1'456,78
mygrid.setNumberFormat("0,000.000",1);//1456.789 => 1'456,789
...

If a column(doesn't matter what type it has) has some assigned statistics counter, format specified for this column will be applied to results of calculation as well. If the type isn't 'edn'/'ron', the format will be applied just to the statistics counter.

Dates

Formatting is set for the whole grid and applied to all columns(cells) of types dhxCalendar and dhxCalendarA.

To set the desired date format you should use the method setDateFormat().
The method takes the only parameter - the date mask.


Table 1 Mask elements
Mask element Description
%d day as number ( with leading zero )
%j day as number
%D abbreviated name of the day
%l full name of the day
%m month as number ( with leading zero )
%n month as number
%M abbreviated name of the month
%F full name of the month
%y year as number (2 digits)
%Y year as number (4 digits)
%H hours (24)
%i minutes

Related sample:  Date/Decimal format


For example, if you want to set June 1, 2011 as 01.06.2011, the following format should be specified:

mygrid.setDateFormat("%d.%m.%Y");
Back to top