1

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?

M.Parent
  • 173
  • 12

2 Answers2

0

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' },...
        ], ...
MilletSoftware
  • 3,521
  • 2
  • 12
  • 15
  • I remember why I could not use this solution. It's because the field value is nested in a subclass and I didn't had the choice of using a template function. But you're right, it should work this way using a simple model. – M.Parent Aug 29 '23 at 21:30
0

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>
M.Parent
  • 173
  • 12