简体   繁体   中英

How to translate ag grid header using ngx-translate

I have an AG-GRID in my application, and I need to translate the header. I tried this solution but it didn't work, it's sad there is no method such refreshHeader()

I was wonderwing how to tranlsate header from ag grid

HTML

 <ag-grid-angular #grid class="ag-theme-alpine" [rowData]="dataSource"
                       rowSelection=single domLayout=autoHeight [pagination]="true"
                       [context]="context" [paginationPageSize]=15 
                       [columnDefs]="columns" 
                       [defaultColDef]="defaultColumnDef">
      </ag-grid-angular>

TS

constructor(private translationService: TranslationService) {}
@ViewChild('grid') dataGrid?: AgGridAngular;
this.columns = [
      { headerName: 'teste', field:'type', sortable: true },
      { headerName: 'idtca'.toUpperCase(), field: 'idtca', sortable: true},
      { headerName: 'Raison', field: 'raison', sortable: true},
   
    ];

Try this...

this.columns = [
    { headerValueGetter: this.headerTranslation('teste'), field:'type', sortable: true },
    { headerValueGetter: this.headerTranslation('Raison'), field: 'raison', sortable: true},
];

Then

headerTranslation(translateKey: string) {
  return () => this.translate.instant(translateKey);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM