Global local in EJ2 JavaScript Grid control

5 Jun 202424 minutes to read

The Syncfusion EJ2 JavaScript Grid control provides a feature known as Globalization (global and local), which makes the application more accessible and useful for individuals from different regions and language backgrounds. You have the ability to view data in your preferred language and format, resulting in an enhanced overall experience.

Localization

The Syncfusion EJ2 JavaScript Grid provides a built-in Localization library, enabling you to customize the text used in the grid to suit different languages or cultural preferences. With this library, you can change static text on various elements, such as group drop area text and pager information text, to different cultures, such as Arabic, Deutsch, French, and more.

This can be achieved by defining the locale property and translation object.

The following list of properties and its values are used in the grid.

Data Rendering

Locale key words Text Example
EmptyRecord No records to display Locale empty record
EmptyDataSourceError DataSource must not be empty at initial load since columns are generated from dataSource in AutoGenerate Column Grid  

Columns

Locale key words Text Example
True true Locale true
False false Locale false
ColumnHeader column header Locale column header
TemplateCell is template cell Locale template cell
ClipBoard clipboard Locale clipboard
CheckBoxLabel checkbox Locale checkbox label

ColumnChooser

Locale key words Text Example
Columnchooser Columns Locale columnchooser
ChooseColumns Choose Column Locale choose columns
ColumnChooserDialogARIA Column chooser Locale columnchooser dialog ARIA

Editing

Locale key words Text Example
Add Add Locale add
Edit Edit Locale edit
Cancel Cancel Locale cancel
Update Update Locale update
Delete Delete Locale delete
Save Save Locale save
EditOperationAlert No records selected for edit operation Locale edit operation alert
DeleteOperationAlert No records selected for delete operation Locale delete operation alert
SaveButton Save Locale save button
OKButton OK Locale ok button
CancelButton Cancel Locale cancel button
EditFormTitle Details of Locale edit form title
AddFormTitle Add New Record Locale add form title
BatchSaveConfirm Are you sure you want to save changes? Locale batch save confirm
BatchSaveLostChanges Unsaved changes will be lost. Are you sure you want to continue? Locale batch save lost changes
ConfirmDelete Are you sure you want to Delete Record? Locale confirm delete
CancelEdit Are you sure you want to Cancel the changes? Locale cancel edit
DialogEditARIA Edit dialog  
CommandColumnAria is Command column column header Locale command column aria
DialogEdit Dialog edit Locale dialog edit

Grouping

Locale key words Text Example
GroupDropArea Drag a column header here to group its column Locale group drop area
UnGroup Click here to ungroup Locale un group
GroupDisable Grouping is disabled for this column Locale group disable
Item item Locale Item
Items items Locale Items
UnGroupButton Click here to ungroup  
GroupDescription Press Ctrl space to group Locale group description
GroupButton Group button Locale group button
UnGroupAria ungroup button Locale ungroup aria
GroupSeperator Separator for the grouped columns Locale group seperator
UnGroupIcon ungroup the grouped column Locale ungroup icon
GroupedSortIcon sort the grouped column Locale grouped sort icon
GroupedDrag Drag the grouped column Locale grouped drag
GroupCaption is groupcaption cell Locale group caption
Expanded Expanded Locale expanded
Collapsed Collapsed Locale collapsed

Filtering

Locale key words Text Example
InvalidFilterMessage Invalid Filter Data  
FilterbarTitle \s filter bar cell Locale filterbar title
Matchs No Matches Found Locale matchs
FilterButton Filter Locale filter button
ClearButton Clear Locale clear button
StartsWith Starts With Locale starts with
EndsWith Ends With Locale ends with
Contains Contains Locale contains
Equal Equal Locale equal
NotEqual Not Equal Locale not equal
LessThan Less Than Locale less than
LessThanOrEqual Less Than Or Equal Locale less than or equal
GreaterThan Greater Than Locale greater than
GreaterThanOrEqual Greater Than Or Equal Locale greater than or equal
ChooseDate Choose a Date Locale choose date
EnterValue Enter the value Locale enter value
SelectAll Select All Locale select all
Blanks Blanks Locale blanks
FilterTrue True Locale filter true
FilterFalse False Locale filter false
NoResult No Matches Found Locale no result
ClearFilter Clear Filter Locale clear filter
NumberFilter Number Filters Locale number filter
TextFilter Text Filters Locale text filter
DateFilter Date Filters Locale date filter
DateTimeFilter DateTime Filters Locale date time filter
MatchCase Match Case Locale match case
Between Between Locale between
CustomFilter Custom Filter Locale custom filter
CustomFilterPlaceHolder Enter the value Locale custom filter placeholder
CustomFilterDatePlaceHolder Choose a date Locale custom filter date placeholder
AND AND Locale AND
OR OR Locale OR
ShowRowsWhere Show rows where: Locale show rows where
NotStartsWith Does Not Start With Locale not starts with
Like Like Locale like
NotEndsWith Does Not End With Locale not ends with
NotContains Does Not Contain Locale not contains
IsNull Null Locale is null
NotNull Not Null Locale not null
IsEmpty Empty Locale is empty
IsNotEmpty Not Empty Locale is not empty
AddCurrentSelection Add current selection to filter Locale add current selection
FilterMenuDialogARIA Filter menu dialog Locale filter menu dialog ARIA
ExcelFilterDialogARIA Excel filter dialog Locale excel menu dialog ARIA
CustomFilterDialogARIA Custom filter dialog Locale Custom filter dialog ARIA
SortAtoZ Sort A to Z Locale sort AtoZ
SortZtoA Sort Z to A Locale sort ZtoA
SortByOldest Sort by Oldest Locale sort by oldest
SortByNewest Sort by Newest Locale sort by newest
SortSmallestToLargest Sort Smallest to Largest Locale sort smallest to largest
SortLargestToSmallest Sort Largest to Smallest Locale sort largest to smallest
FilterDescription Press Alt Down to open filter Menu Locale filter description

Searching

Locale key words Text Example
Search Search Locale search
SearchColumns search columns  
Clear Clear Locale clear

Sorting

Locale key words Text Example
Sort Sort Locale sort
SortDescription Press Enter to sort Locale sort description

Toolbar

Locale key words Text Example
Print Print Locale print
Pdfexport PDF Export Locale pdfexport
Excelexport Excel Export Locale excelexport
Csvexport CSV Export Locale csvexport

ColumnMenu

Locale key words Text Example
FilterMenu Filter Locale filter menu
AutoFitAll Autofit all columns  
AutoFit Autofit this column  
ColumnMenuDialogARIA Column menu dialog Locale columnmenu dialog ARIA
ColumnMenuDescription Press Alt Down to open Column Menu Locale columnmenu description

ContextMenu

Locale key words Text Example
Copy Copy Locale copy
Group Group by this column Locale group
Ungroup Ungroup by this column Locale ungroup
autoFitAll Auto Fit all columns Locale autofit all
autoFit Auto Fit this column Locale autofit
Export Export Locale export
FirstPage First Page Locale first page
LastPage Last Page Locale last page
PreviousPage Previous Page Locale previous page
NextPage Next Page Locale next page
SortAscending Sort Ascending Locale sort ascending
SortDescending Sort Descending Locale sort descending
EditRecord Edit Record Locale edit record
DeleteRecord Delete Record Locale delete record

Pager

Locale key words Text Example
currentPageInfo {0} of {1} pages Locale current page info
totalItemsInfo ({0} items) Locale total items info
firstPageTooltip Go to first page Locale first page tooltip
lastPageTooltip Go to last page Locale last page tooltip
nextPageTooltip Go to next page Locale next page tooltip
previousPageTooltip Go to previous page Locale previous page tooltip
nextPagerTooltip Go to next pager items Locale next pager tooltip
previousPagerTooltip Go to previous pager items Locale previous pager tooltip
pagerDropDown Items per page Locale pager drop down
pagerAllDropDown Items Locale pager all drop down
All All Locale pager all
totalItemInfo ({0} item) Locale total item info
Container Pager Container Locale pager container
Information Pager Information  
ExternalMsg Pager external message Locale pager external msg
Page Page  
Of of Locale pager of
Pages Pages  

Loading translations for de culture

The Syncfusion EJ2 JavaScript Grid control provides a built-in Localization library that allows you to load translation objects for different cultures. By using the load function of the L10n class, you can customize the text content of the Grid to be displayed in different languages.

This feature allows you to specify translation objects for specific cultures, such as Deutsch (German), and display the Grid’s content in the desired language.

The following example demonstrates how to load a translation object for Deutsch (de) culture, by using the load function of L10n class from the ej2-base module and by defining the locale to de-DE.

loadCultureFiles();

function createGrid() {
  var grid = new ej.grids.Grid({
    dataSource: data,
    locale: 'de-DE',
    allowGrouping: true,
    allowPaging: true,
    pageSettings: { pageSize: 6 },
    columns: [
      { field: 'OrderID', headerText: 'Order ID', textAlign: 'Right', width: 90 },
      { field: 'CustomerID', headerText: 'Customer ID', width: 100 },
      { field: 'ShipCity', headerText: 'Ship City', width: 100 },
      { field: 'ShipName', headerText: 'Ship Name', width: 120 }
    ],
    height: 220
  });
  grid.appendTo('#Grid');
}

function loadCultureFiles() {
  var fetch = new ej.base.Fetch('./locale.json', 'GET', false);
  fetch.onSuccess = function (deDELocalization ) {
    ej.base.L10n.load(deDELocalization );
    createGrid(); // Create the grid after loading the culture files
  };
  fetch.send();
}
<!DOCTYPE html><html lang="en"><head>
    <title>EJ2 Grid</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Typescript Grid Control">
    <meta name="author" content="Syncfusion">
    <link href="index.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-base/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-grids/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-buttons/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-popups/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-richtexteditor/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-navigations/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-dropdowns/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-lists/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-inputs/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-calendars/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-notifications/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-splitbuttons/styles/bootstrap5.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/27.2.2/dist/ej2.min.js" type="text/javascript"></script>
<script src="es5-datasource.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
    <div id="container">
        <div id="Grid"></div>
    </div>
<script>
var ele = document.getElementById('container');
if(ele) {
  ele.style.visibility = "visible";
}   
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>

Loading translations for fr culture

The Loading translations feature allows you to specify translation objects for different cultures, such as Deutsch, Arabic, French and display the Grid’s content in the desired language.

The following example demonstrates how to load a translation object for French (fr) culture, by defining the locale to fr-FR and by using the load function of L10n class from the ej2-base module.

loadCultureFiles();

function createGrid() {
  var grid = new ej.grids.Grid({
    dataSource: data,
    locale: 'fr-FR',
    allowGrouping: true,
    allowPaging: true,
    editSettings: {allowEditing: true, allowAdding: true, allowDeleting: true},
    toolbar:['Add', 'Edit', 'Delete', 'Update', 'Cancel', 'Search'],
    pageSettings: { pageSize: 6 },
    columns: [
        { field: 'OrderID', headerText: 'Order ID', textAlign: 'Right', isPrimaryKey: true, width: 90 },
        { field: 'CustomerID', headerText: 'Customer ID', width: 100 },
        { field: 'ShipCity', headerText: 'Ship City', width: 100 },
        { field: 'ShipName', headerText: 'Ship Name', width: 120 }
    ],
    height: 220
  });
  grid.appendTo('#Grid');
}

function loadCultureFiles() {
  var fetch = new ej.base.Fetch('./locale.json', 'GET', false);
  fetch.onSuccess = function (frFRLocalization) {
    ej.base.L10n.load(frFRLocalization );
    createGrid(); // Create the grid after loading the culture files
  };
  fetch.send();
}
<!DOCTYPE html><html lang="en"><head>
    <title>EJ2 Grid</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Typescript Grid Control">
    <meta name="author" content="Syncfusion">
    <link href="index.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-base/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-grids/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-buttons/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-popups/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-richtexteditor/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-navigations/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-dropdowns/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-lists/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-inputs/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-calendars/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-notifications/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-splitbuttons/styles/bootstrap5.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/27.2.2/dist/ej2.min.js" type="text/javascript"></script>
<script src="es5-datasource.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
    <div id="container">
        <div id="Grid"></div>
    </div>
<script>
var ele = document.getElementById('container');
if(ele) {
  ele.style.visibility = "visible";
}   
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>

Switch the different localization

The Synfusion EJ2 JavaScript Grid allows you to switch the localization from one culture to another culture. This will be useful when you want to change the localization based on your requirements.

To switch to a different localization, follow these steps:

Step 1: Import and load the required CLDR (Common Locale Data Repository) data for the desired culture using the loadCldr function.

loadCldr(
    cagregorian,
    currencies,
    numbers,
    timeZoneNames,
    numberingSystems
);

Step 2: To change the default culture and the currency code, you can use the methods setCulture for setting the locale and setCurrencyCode for setting the currency code.

To switch to the French culture and set the currency code as EUR, you can use the setCulture method and the setCurrencyCode method of the Grid on external button click. This is demonstrated below:

loadLocalizationData();
function loadLocalizationData() {
var fetch = new ej.base.Fetch('./locale.json', 'GET', false);
fetch.onSuccess = function (frFRLocalization) {
  ej.base.L10n.load(frFRLocalization );
  loadCultureFiles(); 
};
fetch.send();
}

  var grid = new ej.grids.Grid({
    dataSource: data,
    allowPaging: true,
    columns: [
        { field: 'OrderID', headerText: 'Order ID', textAlign: 'Right', width: 90 },
        { field: 'CustomerID', headerText: 'Customer ID', width: 100 },
        { field: 'Freight', headerText: 'Freight', format: 'C2', width: 90 },
        { field: 'ShipCountry', headerText: 'Ship Country', width: 100 }
    ],
    height: 220
  });
  grid.appendTo('#Grid');

function loadCultureFiles() {
  var files = ['ca-gregorian.json', 'numbers.json', 'currencies.json', 'timeZoneNames.json', 'numberingSystems.json'];
  var loadCulture = function (prop) {
    var fetch = new ej.base.Fetch('./' + files[prop], 'GET', false);
    fetch.onSuccess = function (response) {
        if (typeof response=== 'object') {
         // If the response is an object, convert it to a JSON string
          var jsonString = JSON.stringify(response);
          ej.base.loadCldr(JSON.parse(jsonString));
        } else if (typeof response=== 'string') {
          // If the response is already a JSON string, parse and load it
          ej.base.loadCldr(JSON.parse(response));

        } else {
          console.error('Invalid responsetype received:', response);
        }
        ej.base.setCulture('fr-FR'); // Change the Grid culture
        ej.base.setCurrencyCode('EUR');
      };
    fetch.send();
  };
  for (var prop = 0; prop < files.length; prop++) {
    loadCulture(prop);
  }
}

var FrButton = new ej.buttons.Button({ cssClass: 'e-outline' }, '#frButton');
document.getElementById('frButton').onclick = function() {
  ej.base.setCulture('fr-FR'); // Change the Grid culture to French locale
  ej.base.setCurrencyCode('EUR'); // Change the currency code based on French culture
};

var EnButton = new ej.buttons.Button({ cssClass: 'e-outline' }, '#enButton');
document.getElementById('enButton').onclick = function() {
  ej.base.setCulture('en-US'); // Change the Grid culture to English locale
  ej.base.setCurrencyCode('USD'); // Change the currency code based on American English culture
}
<!DOCTYPE html><html lang="en"><head>
    <title>EJ2 Grid</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Typescript Grid Control">
    <meta name="author" content="Syncfusion">
    <link href="index.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-base/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-grids/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-buttons/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-popups/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-richtexteditor/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-navigations/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-dropdowns/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-lists/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-inputs/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-calendars/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-notifications/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-splitbuttons/styles/bootstrap5.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/27.2.2/dist/ej2.min.js" type="text/javascript"></script>
<script src="es5-datasource.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
    <div id="container">
        <button id="frButton">Change FR Locale</button>
        <button id="enButton">Change En Locale</button>
        <div id="Grid"></div>
    </div>
<script>
var ele = document.getElementById('container');
if(ele) {
  ele.style.visibility = "visible";
}   
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>

Internationalization

The Internationalization library in the Syncfusion EJ2 JavaScript Grid provides a localized display of number, date, and time values in the Grid control based on the preferred language and region.

Internationalization library allows you to globalize number, date, and time values using format strings defined in the columns.format property.

You need to load the culture format files corresponding to the desired locale. This ensures that the Grid control uses the correct format strings for number, date, and time values based on the selected culture. This can be demonstrated in the below example,

loadLocalizationData();
function loadLocalizationData() {
    var fetch = new ej.base.Fetch('./locale.json', 'GET', false);
    fetch.onSuccess = function(deDELocalization) {
      ej.base.L10n.load(deDELocalization );
      loadCultureFiles(); 
    };
    fetch.send();
 }

var formatOptions={ format: 'C2', useGrouping: false, minimumSignificantDigits: 1, maximumSignificantDigits: 3 };
  var grid = new ej.grids.Grid({
    dataSource: data,
    allowPaging: true,
    allowGrouping: true,
    columns: [
        { field: 'OrderID', headerText: 'Order ID', textAlign: 'Right', width: 120 },
        { field: 'CustomerID', headerText: 'Customer ID', width: 100 },
        { field: 'Freight', headerText: 'Freight', textAlign: 'Right', format: formatOptions , width: 80 },
        { field: 'ShipName', headerText: 'Ship Name', width: 120 }
    ],
    height: 220
  });
  grid.appendTo('#Grid');

function loadCultureFiles() {
  var files = ['ca-gregorian.json', 'numbers.json', 'currencies.json', 'timeZoneNames.json', 'numberingSystems.json'];
  var loadCulture = function (prop) {
    var fetch = new ej.base.Fetch('./' + files[prop], 'GET', false);
    fetch.onSuccess = function (response) {
        if (typeof response=== 'object') {
         // If the response is an object, convert it to a JSON string
          var jsonString = JSON.stringify(response);
          ej.base.loadCldr(JSON.parse(jsonString));
        } else if (typeof response=== 'string') {
          // If the response is already a JSON string, parse and load it
          ej.base.loadCldr(JSON.parse(response));

        } else {
          console.error('Invalid responsetype received:', response);
        }
        ej.base.setCulture('de-DE'); // Change the Grid culture
        ej.base.setCurrencyCode('EUR');
      };
    fetch.send();
  };
  for (var prop = 0; prop < files.length; prop++) {
    loadCulture(prop);
  }
}
<!DOCTYPE html><html lang="en"><head>
    <title>EJ2 Grid</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Typescript Grid Control">
    <meta name="author" content="Syncfusion">
    <link href="index.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-base/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-grids/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-buttons/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-popups/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-richtexteditor/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-navigations/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-dropdowns/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-lists/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-inputs/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-calendars/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-notifications/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-splitbuttons/styles/bootstrap5.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/27.2.2/dist/ej2.min.js" type="text/javascript"></script>
<script src="es5-datasource.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
    <div id="container">
        <div id="Grid"></div>
    </div>
<script>
var ele = document.getElementById('container');
if(ele) {
  ele.style.visibility = "visible";
}   
      </script>
<script src="index.js" type="text/javascript"></script>
</body></html>

  • In the above sample, Freight column is formatted using the NumberFormatOptions.
  • By default, locale value is en-US. If you wish to change the culture to something other than en-US, you can simply set the locale property accordingly.

Right to Left - RTL

The Right to Left (RTL) feature in the Syncfusion EJ2 JavaScript Grid allows you to switch the text direction and layout from left-to-right to right-to-left. This feature is especially beneficial for interacting with the grid in languages that are written and read from right to left, such as Arabic, Farsi, Urdu, and others. Enabling RTL significantly improves the experience and accessibility for such languages.

To enable RTL in the Grid, you need to set the enableRtl property to true. By setting enableRtl, the grid control’s text direction and layout will be adjusted to support right-to-left languages.

In the following example, the EJ2 Toggle Switch Button control is added to enable or diable the Right to Left (RTL) feature for the Arabic (ar-AE) locale. When the switch is toggled, the change event is triggered and the enableRtl property of the grid is updated accordingly.

loadLocalizationData();
function loadLocalizationData() {
    var fetch = new ej.base.Fetch('./locale.json', 'GET', false);
    fetch.onSuccess = function(arAELocalization) {
      ej.base.L10n.load(arAELocalization);
      createGrid();
    };
    fetch.send();
 }
function createGrid(){
var grid = new ej.grids.Grid({
    dataSource: data,
    enableRtl: true,
    locale: 'ar-AE',
    allowSorting: true,
    allowReordering: true,
    allowFiltering: true,
    allowGrouping: true,
    editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true, mode:'Normal' },
    toolbar:  ['Add', 'Edit', 'Delete', 'Update', 'Cancel'],
    allowPaging: true,
    pageSettings: { pageSize: 7 },
    showColumnMenu: true,
    showColumnChooser: true,
    columns: [
        { field: 'OrderID', headerText: 'Order ID', textAlign: 'Right', isPrimaryKey: true, width: 90 },
        { field: 'CustomerID', headerText: 'Customer ID', width: 100 },
        { field: 'ShipCity', headerText: 'Ship City', width: 100 },
        { field: 'ShipName', headerText: 'Ship Name', width: 120 }
    ],
});
grid.appendTo('#Grid');

var switchObj = new ej.buttons.Switch({ 
    change: onSwitchChange
 });
switchObj.appendTo('#switch');

function onSwitchChange(args){
    if (args.checked) {
        grid.enableRtl = false;
      } else {
        grid.enableRtl = true;
      }
}
}
<!DOCTYPE html><html lang="en"><head>
    <title>EJ2 Grid</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Typescript Grid Control">
    <meta name="author" content="Syncfusion">
    <link href="index.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-base/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-grids/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-buttons/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-popups/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-richtexteditor/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-navigations/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-dropdowns/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-lists/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-inputs/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-calendars/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-notifications/styles/bootstrap5.css" rel="stylesheet">
    <link href="https://cdn.syncfusion.com/ej2/27.2.2/ej2-splitbuttons/styles/bootstrap5.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/27.2.2/dist/ej2.min.js" type="text/javascript"></script>
<script src="es5-datasource.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
    
    <div id="container">
        <label>Enable or diable RTL mode</label>
        <input id="switch" type="checkbox"/>
        <div style="padding: 5px 5px" id='Grid'></div>
    </div>

<script>
var ele = document.getElementById('container');
if(ele) {
  ele.style.visibility = "visible";
}   
      </script>
<script src="index.js" type="text/javascript"></script>
</body></html>

See Also