[CLOSED] Number grid column format

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] Number grid column format

    Hi,

    What is the recommended method for formatting (client side) numeric grid columns
    using the current culture settings?

    Thanks,
    Stefano
    Last edited by Daniil; Oct 27, 2010 at 10:13 AM. Reason: [CLOSED]
  2. #2
    Hi,

    To format numeric data in a grid you could use either the <ext:NumberColumn> control or the common <ext:Column> with a custom renderer.

    If you need an example please provide more details about your requirement.
  3. #3
    Hi,

    I just want to see a grid colum number in the format of the current culture.
    For example, if the currently selected culture is it-IT I would like to see a numeric value
    in the format n.nnn,nn ( '.' is the thousands separator and ',' is the decimal separator).


    Bye,
    Stefano
  4. #4
    Please use <ext:NumberColumn>.
    An appropriate value of NumberColumn's Format property you could set in code behind.
  5. #5
    Hi Daniil ,

    ok, but why, for example, <ext:DateColumn> uses the default format of the current culture while <ext:NumberColumn> does not?

    It seems more logical to always use the default format and use other formats only when necessary.

    Bye,
    Stefano
  6. #6
    Hi,

    A DateColumn's format is changed in localization scripts (extjs\locale\ext-lang-it.js).
    But, unfortunately, localization of NumberColumn is done only for en and de.

    You can look into localization scripts to understand how it works.
  7. #7
    Ok Daniil,

    I decided to use the following method to properly format my numeric columns, and call it from a renderer function:

     
     Number.prototype.toFormattedString = function (decimals) {
      var theNumber = this,
      decimalPlaces = isNaN(decimals) ? 2 : Math.abs(decimals),
      decimalSeparator = (1234.5).toLocaleString().substring(5, 6),
      thousandsSeparator = (1234.5).toLocaleString().substring(1, 2),
      sign = (theNumber < 0) ? '-' : '',
      i = parseInt(theNumber = Math.abs(theNumber).toFixed(decimalPlaces)) + '',
      j = ((j = i.length) > 3) ? j % 3 : 0;
      return sign + (j ? i.substr(0, j) + thousandsSeparator : '') + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousandsSeparator) + (decimalPlaces ? decimalSeparator + Math.abs(theNumber - i).toFixed(decimalPlaces).slice(2) : '');
     };
    Could you suggest me what is the best method to have it available on all pages of my (MVC) application,
    without having to include the code on every page?

    Thanks,
    Stefano
  8. #8
    Hi,

    I reccoment to move the fix to the external js file and attach the js file to the master page or another base page
  9. #9
    Hi,

    Unfortunately, my solution does not work with Google Chrome (toLocaleString() on Chrome is not supported).

    Bye
    Stefano
  10. #10
    Hi,

    Yes, there is an issue in Chrome.
    http://code.google.com/p/chromium/issues/detail?id=3607

    The bug is too old therefore I don't hope it would be fixed soon.

    To workaround it I would suggest you to use this ExtJS class
    http://dev.sencha.com/deploy/dev/docs/?class=Date

    By the way for cross-browser compatibility it's recommended to use ExtJS where possible .
    Just ExtJS team makes a lot of work for that.
Page 1 of 2 12 LastLast

Similar Threads

  1. Format Number in GridPanel Template Column
    By pooja in forum 1.x Help
    Replies: 0
    Last Post: May 04, 2012, 9:43 AM
  2. [CLOSED] number renderer in grid column
    By Vasudhaika in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Dec 05, 2010, 10:01 AM
  3. [CLOSED] [1.0] Number format in Grid Column
    By bsnezw in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Feb 09, 2010, 1:06 PM
  4. Link in Grid with format number
    By bsnezw in forum 1.x Help
    Replies: 2
    Last Post: Oct 26, 2009, 2:50 PM
  5. how to set the grid column format as Float
    By Dinesh.T in forum 1.x Help
    Replies: 0
    Last Post: Jul 09, 2009, 10:03 AM

Posting Permissions