skip to Main Content

I’m using the ej2 javascript Grid by Syncfusion. The following is a simplification of the actual code.
In the grid definition I have a column having a template, like this :

{ field: "Quantity", headerText: "Quantity", template: "#colQuantity" },

<script id="colQuantity" type="text/x-template">
    ${quantity}
</script>

What I want to achieve here is to have a format "N4" in the quantity field, so the value is prettier. Is there a way to add a .toFixed(4) or a format("N4") somewhere in the template, or a way to rewrite this template so the format is applied?

2

Answers


  1. Chosen as BEST ANSWER

    I found that a template can call a javascript function and pass in data. The following code made it work.

    <script>
        function formatNumber(args) {
            return args.quantity.toFixed(4);
        }
    </script>
    
    <script id="colQuantity" type="text/x-template">
        ${formatNumber(data)}
    </script>
    

  2. In the columns definition for the grid, in the definition for that column, use something like:

    ...
    , columns: [ ...
             { field: 'Quantity', headerText: 'Quantity', width: 120, clipMode: 'EllipsisWithTooltip', type: 'string', format: 'N4', textAlign: 'Right' },...
            ], ...
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search