Ngx translate pipe for header text in Angular Grid component

4 Apr 20233 minutes to read

You can use the ngx-translate to translate the headerText of grid’s column. This can be achieved by using the translate pipe for headerText property.

This is demonstrated in the below sample code where translate is applied to headerText property of the grid columns,

import { Component } from '@angular/core';  
import {TranslateService} from '@ngx-translate/core';  
    selector: 'app-container',
    template: `<ejs-grid id="Grid" [dataSource]="dataSource" allowPaging="true">  
                        <e-column field="OrderID" [isPrimaryKey]="true" headerText="Id"></e-column>
                        <e-column field="CustomerID" headerText="Value"></e-column>

export class AppComponent implements OnInit {

    constructor(translate: TranslateService) {
        // Specifies the available languages to the service
        translate.addLangs(['en', 'fr'])
        // Specifies the current languages to the service

    public dataSource: any = [
      OrderID: 10248, CustomerID: 'VINET', OrderDate: new Date(8364186e5),
      OrderID: 10249, CustomerID: 'TOMSP', OrderDate: new Date(836505e6),

Import the required modules in app.module.ts file along with translate loader function,

import {BrowserModule} from '@angular/platform-browser';
import {NgModule} from '@angular/core';
import {GridAllModule} from '@syncfusion/ej2-angular-grids';

import {AppComponent} from './app.component';
import {TranslateLoader, TranslateModule} from '@ngx-translate/core';
import {HttpClientModule, HttpClient} from '@angular/common/http';
import {TranslateHttpLoader} from '@ngx-translate/http-loader';

export function createTranslateLoader(http: HttpClient) {
  return new TranslateHttpLoader(http, './assets/i18n/', '.json');

  declarations: [
  imports: [
      loader: {
        provide: TranslateLoader,
        useFactory: (createTranslateLoader),
        deps: [HttpClient]
  bootstrap: [AppComponent]
export class AppModule { }

Then add the json file with the translation text in the required languages,


    "Value": "Order ID!",
    "Id": "Customer ID"

    "Value": "numéro de commande!",
    "Id": "N ° de client"

Angular 5 sample