Flexgrid default format number

Posted by: htn on 2 May 2021, 5:51 pm EST

    • Post Options:
    • Link

    Posted 2 May 2021, 5:51 pm EST

    Hi,

    I would like to change the default format number of flexgrid for all columns to something without thousand seperator (such as ‘f’).

    I know that we can set it for each column, however, I want to do it once for a flexgrid, so that if we add a new column of type number, we don’t need to add the format for the definition. Is there any way to do it?

  • Posted 3 May 2021, 11:01 pm EST

    Hi Hoang,

    To achieve the required functionality you may handle the collectionChanged event on the grid’s column collection to change the format of newly added columns.

    You may refer to the below code sample demonstrating the same -

    https://stackblitz.com/edit/vanilla-js-simple-drag-de2qqs?file=index.js

    Regards,

    Ashwin

  • Posted 4 May 2021, 12:07 am EST

    Hi Ashwin,

    Thank you for your answer. That’s not exactly what I was looking for. I was not clear enough.

    Let’s say in my case, I already have have the grid definition such as:

    
      const collectionView = new CollectionView([]);
      const grid = new FlexGrid("#theGrid", {
        itemsSource: collectionView,
        columns: [{
          name: 'country',
          binding: 'country',
        }, {
          name: 'downloads',
          binding: 'downloads',
        }, {
          name: 'sales',
          binding: 'sales',
        }, {
          name: 'numbers',
          binding: 'numbers',
          format: 'D',
        }],
      });
    
    

    As you can see, except the ‘country’ column, I have 3 columns with explicit dataType number. However, the initial data is empty (dataType will not be detected at the creation time), and data will be added later to the collectionView.

    What I want to achieve is: I want the default format for number (columns ‘downloads’ and ‘sales’) would be ‘f’, and the column ‘numbers’ format will be ‘D’ as specified.

  • Posted 4 May 2021, 8:42 pm EST

    Hi,

    Thanks for the detailed information. Unfortunately, there is no way by which the generated column will have the f format by default. We will need to iterate over each of the initial columns and update its format.

    You can use the itemsSourceChanged event to update the format of the initial columns and the collectionChanged event of the columns array to update the format of the subsequent columns. Please refer to the updated sample below:

    https://stackblitz.com/edit/vanilla-js-simple-drag-bpewyf

    Let me know if this helps or otherwise.

    ~regards

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels