Format Number for Grid cells inside Javascript

I am unable to format numbers for Grid cell values in Java script.  I searched various forums but could not find anything.  I use the below code to format datetime .

        var intl = new ej.base.Internationalization();
        var dFormatter = intl.getDateFormat({
            format : 'MMM dd,yyyy HH:mm',
            type : 'dateTime'
        });
        var formattedString = dFormatter(new Date(args.value));

I need to format a number using format : '00#########' inside a javascript . Please let me know how to do it.

5 Replies

AG Ajith Govarthan Syncfusion Team November 13, 2020 01:00 PM UTC

Hi NAVEEN, 
 
Thanks for contacting Syncfusion support. 
 
Based on your you want to format the number and date values in the grid component. Before we proceed to your query, we need more details on your requirement so please share the below details to validate further on your requirement. 
 
  1. Share complete grid code example
 
  1. Please let us know that you want to apply number and date format while editing the records.
 
  1. Share the screenshot of your requirement.
 
  1. Share the Syncfusion package version.
 
Regards, 
Ajith G. 



NR NAVEEN RAAJU November 14, 2020 05:25 AM UTC

Sorry for not providing much details.  We have a column called 'CSI' of type numeric and format of this column set to '00#########'.  This column needs a template to add a Javascript click event . So within the template, the column value for CSI is not properly formatted with '00#########'.  The leading zeros does not appear .

I have attached the zip file . Please run MyProfile_Cares_EJ2Grid.html to reflect the issue.


Attachment: Cares_DataTableStatic_ca413863.zip


VS Vignesh Sivagnanam Syncfusion Team November 16, 2020 11:05 AM UTC

Hi Naveen, 

Thanks for the update 

Based on your update we found that you want to apply the format to the column template. You can apply the format to the column template in the grid using the custom function. Please refer the below Code snippet and sample for your reference 

Code Example : 
import { Internationalization } from "@syncfusion/ej2-base"; 

let instance: Internationalization = new Internationalization(); 

………. 

(window as DateFormat).format = (value: Number) => { 
  return instance.formatNumber(value, { format: "00#########" }); 
}; 

interface DateFormat extends Window { 
  format?: Function; 
} 
……… 
……… 
      field: "CSI", 
      template: "<div>${format(Freight)}</div>", 
      headerText: "CSI", 
      type: "number", 
      width: 130 
    }, 



Regards, 
Vignesh Sivagnanam 



NR NAVEEN RAAJU November 17, 2020 12:41 AM UTC

Thanks much for your quick assistance. Its working fine now.


VS Vignesh Sivagnanam Syncfusion Team November 17, 2020 09:52 AM UTC

Hi Naveen,  

We are happy to hear that the provided solution works fine at your end.  

Please get back to us if you need any further assistance.  

Regards,  
Vignesh Sivagnanam  


Loader.
Up arrow icon