Column Template

Hi,

I have a Rating column of type double in the grid. I created a template and typed the following:

${Rating.toFixed(2)}

but it doesn't work. I need to show 2 decimal places for the Rating column in the grid.

Any help would be appreciated.

Thanks,
Leo


3 Replies

VA Venkatesh Ayothi Raman Syncfusion Team August 6, 2018 11:05 AM UTC

Hi Leonid, 
 
Thanks for using Syncfusion products. 
 
 
As from your query, we suspect that would you like show the decimal values with two decimal places. For e.g, if Rating column value is 5.2332 then we need to display the value 5.23. If so, we suggest you to following two ways, 
 
1)      Default Number format: 
We have built-in support of number format to display the decimal values based like as follows, 
<ejs-grid id="Grid"> 
     
. .  . 
 
    <e-grid-columns> 
 
. .   . 
        <e-grid-column field="Freight" headerText="Freight" textAlign="Right"  format="N2" width="140"></e-grid-column> 
       .  .   . 
    </e-grid-columns> 
</ejs-grid> 
 
 
 
2)      Using column template: 
If you would like to change the decimal places value using column template feature then we suggest you to use custom helper function and parse the number using our Internalization method like as follows, 
<ejs-grid id="Grid"> 
     
. .  . 
 
    <e-grid-columns> 
 
. .   . 
        <e-grid-column field="Freight" headerText="Freight" textAlign="Right"  template="#template" width="140"></e-grid-column> 
       .  .   . 
    </e-grid-columns> 
</ejs-grid> 
 
[template] 
<script type="text/x-template" id="template"> 
 
    
    <span><i>${convert(data)}</i></span> 
</script> 
 
[helper function] 
function convert(data) { 
        var intl = new ej.base.Internationalization(); 
        var formattedValue = intl.parseNumber(data.Freight.toString(), { format: 'N2', minimumIntegerDigits: 8 }); 
       
       return formattedValue; 
        } 
 
Please refer to the following help documentation for more information, 
 
We have also prepared a sample for your convenience which can be download from following link, 
 
 
Note: In that sample, we have used column template for change the decimal places values. 
 
Please let us know if you have any further assistance on this. 
 
 
Regards, 
Venkatesh Ayothiraman. 



PA Panora August 7, 2018 06:12 AM UTC

This works! Thank you very much for your help.


MF Mohammed Farook J Syncfusion Team August 8, 2018 12:00 PM UTC

Hi Leonid, 
Thanks for your update. 
 
We are happy to hear that the provided solution has been resolved your problem. 
 
Regards,
J Mohammed  Farook
 


Loader.
Up arrow icon