Set Local Currency, Number and Data Format

Hi,

I am not able to create a suitable JS file to format the currency (R$), numbers (#. ###, ##) and dates (dd / MM / yyyy) appropriately for pt-BR.

Attached is the file I created for the translation of the components.

Is it possible to adjust the format of this mode? How?

Thank you!

Attachment: ej2.translation.ptBR_981b3bea.zip

3 Replies

LR Logesh Rajappa Syncfusion Team July 24, 2018 02:10 PM UTC

Hi Maico, 

Thanks for contacting Syncfusion support. 

Query: “Is it possible to adjust the format of this mode?” 
 
Yes, it is possible to format the date, number and currency fields for different culture in the grid. To achieve your requirement, we have used format property of the grid. To format the currency field we have used Format(“R$ #”). We have used Load event to format the number and date fields, in that function date format is set to the OrderDate column and number format is set to the EmployeeID column. Using loadCldr method custom culture is loaded for the number format. Please refer to the sample and documentation for your reference. 

[index.cshtml] 
<div> 
... 
    @Html.EJS().Grid("Grid").DataSource(dataManager => { dataManager.Url("/Home/UrlDatasource").UpdateUrl("/Home/Update").InsertUrl("/Home/Insert").RemoveUrl("/Home/Delete").Adaptor("UrlAdaptor"); }).AllowPaging(true).Width("auto").Load("onload").Columns(col => 
{ 
... 
    col.Field("EmployeeID").HeaderText("EmployeeID").AllowEditing(true).Add(); 
    col.Field("Freight").HeaderText("Freight").AllowEditing(true).Format("R$ #").Add(); 
    col.Field("OrderDate").HeaderText("Order Date").AllowEditing(true).Format("yMMMd").Add(); 
}).Render() 
</div> 
 
<script> 
    function onload(args) { 
        loadCultureFiles('en');           //loading the custom culture files with its name as a parameter 
        for (var i = 0; i < this.getColumns().length; i++) { 
            if (this.getColumns()[i].field == 'EmployeeID') {   //checking EmployeeID for number Format 
 
                this.getColumns()[i].format = { format: "n2", useGrouping: trueminimumFractionDigits: 2, maximumFractionDigits: 8 }; 
            } 
            if (this.getColumns()[i].field == 'OrderDate') {     //checking OrderDate for date Frmat 
                this.getColumns()[i].format = {type: "date" , format: "dd/MM/yyyy"} 
            } 
        } 
 
    } 
    function loadCultureFiles(name) { 
        var files = ['ca-date.json','decimal.json']; 
 
        var loadCulture = function (prop) { 
            var val, ajax; 
                ajax = new ej.base.Ajax(location.origin + '/../../scripts/cldr/main/' + name + '/' + files[prop], 'GET', false);  //File location needs to be edited accordingly 
            ajax.onSuccess = function (value) { 
                val = value; 
            }; 
            ajax.send(); 
            ej.base.loadCldr(JSON.parse(val)); 
        }; 
        for (var prop = 0; prop < files.length; prop++) { 
            loadCulture(prop); 
        } 
    } 
</script> 

[decimal.json] 
{ 
  "main": { 
    "pt-BR": {     //culture file 
      "identity": { 
        "version": { 
          "_number": "$Revision: 13050 $", 
          "_cldrVersion": "30.0.2" 
        }, 
        "language": "en" 
      }, 
      "numbers": { 
        "defaultNumberingSystem": "latn", 
        "otherNumberingSystems": { 
          "native": "latn" 
        }, 
        "minimumGroupingDigits": "1", 
        "symbols-numberSystem-latn": { 
          "decimal": ",",     //’.’ Is replaced as ‘,’ 
          "group": ".", 
          "list": ";", 
          "percentSign": "%", 
... 
} 

Note: Please change the downloaded CLDR file’s pt-BR culture name to en-US as it is a workaround to achieve your requirement(Replaced ‘.’ As ‘,’). 
 


Please get back to for further assistance. 

Regards, 
Logesh Rajappa 



MS Maico Schmitz August 3, 2018 12:12 PM UTC

Hi Logesh,

     Worked perfectly.

Thank you so much!


VA Venkatesh Ayothi Raman Syncfusion Team August 6, 2018 03:45 AM UTC

 
Hi Maico, 
 
Thanks for the feedback. 
 
We are very happy to hear that your requirement is achieved. Please let us know if you have any further assistance on this. 
 
 
Regards, 
Venkatesh Ayothiraman. 


Loader.
Up arrow icon