Ngx-datatable: How is the localization of the texts make.

Created on 12 Nov 2017  路  3Comments  路  Source: swimlane/ngx-datatable

Hello,
I read:
Static messages in the table you can override for localization.
emptyMessage: 'No data to display',
totalMessage: 'total'

I try:
import { NgxDatatableModule } from '@swimlane/ngx-datatable';

ngOnInit() {
NgxDatatableModule. but there are no emptyMessage or totalMessage properties for change the text.

Thanks for your help.

regards

Most helpful comment

The messages are bound to a field which by default is called messages. This object has emptyMessage etc as fields. These are read by the ngx-datatable.

You can override this default messages as such:

  <ngx-datatable
    [messages]="my_messages"

you can then populate the object in the component:

  my_messages = {
    'emptyMessage': '',
    'totalMessage': ''
  };

  constructor(private translate: TranslateService) {
    translate.get('LIST_TOTAL', {value: ''})
      .subscribe((res: string) => this.my_messages.totalMessage = res);
    translate.get('LIST_NO_RESULTS', {value: ''})
      .subscribe((res: string) => this.my_messages.emptyMessage = res);
  }
}

where LIST_TOTAL is a key in the messages

All 3 comments

The messages are bound to a field which by default is called messages. This object has emptyMessage etc as fields. These are read by the ngx-datatable.

You can override this default messages as such:

  <ngx-datatable
    [messages]="my_messages"

you can then populate the object in the component:

  my_messages = {
    'emptyMessage': '',
    'totalMessage': ''
  };

  constructor(private translate: TranslateService) {
    translate.get('LIST_TOTAL', {value: ''})
      .subscribe((res: string) => this.my_messages.totalMessage = res);
    translate.get('LIST_NO_RESULTS', {value: ''})
      .subscribe((res: string) => this.my_messages.emptyMessage = res);
  }
}

where LIST_TOTAL is a key in the messages

Even better, it can be done in the markup.
See: https://github.com/swimlane/ngx-datatable/issues/589#issuecomment-300906484

@jeroenwijdemans Your example only applies to ngx-datatable, it doesn't work that way with Angular's built-in i18n (that I'm using). We'd need to have a DOM element to apply the i18n directive on it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JanStock picture JanStock  路  3Comments

paritosh64ce picture paritosh64ce  路  3Comments

Matthi0uw picture Matthi0uw  路  3Comments

rotemx picture rotemx  路  3Comments

ChanBen picture ChanBen  路  3Comments