Changing language at runtime without table destroy in 2.0.0

Changing language at runtime without table destroy in 2.0.0

mdellanave83mdellanave83 Posts: 33Questions: 3Answers: 0
edited March 13 in Free community support

Hi,
I'm trying to localize the dataTable without recreating it.

In the previous versions of dataTable I was able to modify in runtime

jQuery.fn.dataTable.settings[0].oLanguage['sEmptyTable'] = 'my localized text'

And the localized text was updated after the draw method call on the table.

Now, in dataTables 2.x.x I noticed 2 facts:
- the name of the localized properties are changed: for example sEmptyTable became emptyTable but for some reasons in the settings[0].oLanguage object those properties are renamed again in the s format (emptyTable became sEmptyTable)
- the paginator is not rendered with the actual localizad text if I call the draw method (instead, the emptyTable localized text is correctly rendered)

this is my current config in dt 2.x.x

{
  "decimal": "",
  "emptyTable": "No data available",
  "sEmptyTable": "No data available",
  "info": "Showing _START_ to _END_ of _TOTAL_ entries",
  "sInfo": "Showing _START_ to _END_ of _TOTAL_ entries",
  "infoEmpty": "No entries",
  "sInfoEmpty": "No entries",
  "infoFiltered": "(filtered from _MAX_ total entries)",
  "infoPostFix": "",
  "thousands": ",",
  "lengthMenu": "Show _MENU_ entries",
  "loadingRecords": "Loading...",
  "processing": "",
  "search": "Search:",
  "zeroRecords": "No matching records found",
  "paginate": {
    "first": "<i class='fas fa-angles-left'></i>",
    "last": "<i class='fas fa-angles-right'></i>",
    "next": "<i class='fas fa-angle-right'></i>",
    "previous": "<i class='fas fa-angle-left'></i>"
  },
  "aria": {
    "orderable": "Order by this column",
    "orderableReverse": "Reverse order this column"
  }
}

this was my previous

{
  "sEmptyTable": "No data available",
  "sInfo": "Showing _START_ to _END_ of _TOTAL_ entries",
  "sInfoEmpty": "Showing 0 to 0 of 0 entries",
  "sInfoFiltered": "(filtered from _MAX_ total entries)",
  "sInfoPostFix": "",
  "sInfoThousands": ",",
  "sLengthMenu": "Display _MENU_",
  "sLoadingRecords": "Loading...",
  "sProcessing": "Processing...",
  "sSearch": "Search:",
  "sZeroRecords": "No matching records found",
  "oPaginate": {
    "sFirst": "<i class='fas fa-angles-left'></i>",
    "sLast": "<i class='fas fa-angles-right'></i>",
    "sNext": "<i class='fas fa-angle-right'></i>",
    "sPrevious": "<i class='fas fa-angle-left'></i>"
  },
  "oAria": {
    "sSortAscending": ": activate to sort column ascending",
    "sSortDescending": ": activate to sort column descending"
  }
}

Any idea?
Is there a better way to reach my goal?

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    No sorry. Changing the internal settings has never been supported. They can, will and do change, as you have seen. Unfortunately, there is no public API to change language strings after initialisation yet.

    If there is enough demand from the community for it, then I can look into that.

    At this time, you need to destroy the table and reinitialise it if you need to change the language strings.

    Allan

  • mdellanave83mdellanave83 Posts: 33Questions: 3Answers: 0

    Thank you for the answer @allan!

    For some reason I can tell you it was working.

    I think it would be a better approach than reinitializing the table because of the complexity of the params that a new init could require.

    In my use case, the component that change the dataTable localization doesn't know anything about the init params wich the table was built.

Sign In or Register to comment.