Component Sample
import { Component, OnInit, Injectable } from '@angular/core';
import { Column, Editors, Formatter, Formatters, GridExtraService, GridExtraUtils, GridOption, OnEventArgs, ResizerService } from 'angular-slickgrid';
import { TranslateService } from '@ngx-translate/core';
@Component({
templateUrl: './grid-localization.component.html'
})
@Injectable()
export class Example implements OnInit {
gridOptions: GridOption;
columnDefinitions: Column[];
dataset: any[];
constructor(private translate: TranslateService) {
// define the grid options & columns and then create the grid itself
this.defineGrid();
}
// Define grid Options and Columns
// provide a nameKey for each column and enableTranslate to True in GridOption
defineGrid() {
this.columnDefinitions = [
{ id: 'title', name: 'Title', field: 'title', nameKey: 'TITLE', formatter: this.taskTranslateFormatter, sortable: true, minWidth: 100 },
{ id: 'duration', name: 'Duration (days)', field: 'duration', nameKey: 'DURATION', sortable: true, minWidth: 100 },
{ id: 'start', name: 'Start', field: 'start', nameKey: 'START', formatter: Formatters.dateIso, minWidth: 100 },
{ id: 'finish', name: 'Finish', field: 'finish', nameKey: 'FINISH', formatter: Formatters.dateIso, minWidth: 100 },
{ id: 'completed', name: 'Completed', field: 'completed', nameKey: 'COMPLETED', formatter: Formatters.translate, sortable: true, minWidth: 100 }
// OR via your own custom translate formatter
// { id: 'completed', name: 'Completed', field: 'completed', nameKey: 'COMPLETED', formatter: translateFormatter, sortable: true, minWidth: 100 }
];
this.gridOptions = {
autoResize: {
containerId: 'demo-container',
sidePadding: 15
},
enableAutoResize: true,
enableTranslate: true,
i18n: this.translate
};
}
}
// create a custom translate Formatter
taskTranslateFormatter: Formatter = (row, cell, value, columnDef, dataContext) => {
return this.translate('TASK_X', { x: value });
}Last updated