How to use i18n() out site datatables?

How to use i18n() out site datatables?

pisislerpisisler Posts: 106Questions: 21Answers: 1
edited April 2021 in Free community support

I would like to move column and field definitions (of editor) to a standalone JS file like:

var dte_fields = [
   { label: 'Full Name', name: 'full_name' },
   { label: 'City', name: 'city' }
]

And that works very well. The only problem is, I can not get to use i18n(), because as you could guess, DataTables hasn't instantiated yet (as I can not instantiate without first defining the columns since I am using an external JS file rather than inline). Is it possible to use DataTables i18n() outsite DataTables scope to localize labels?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin
    Answer ✓

    Sorry, that won’t be possible as the i18n() method specifically uses the language options that have been configured for the DataTables instance (called the “context” in the terminology we use in the code).

    This is the method in question and you’ll see the first thing it does is get the language values configures for the instance from the context.

    If you wanted to have that sort of functionality without a DataTables instance though, you could use the code from that function to built a little i18n function.

    Allan

This discussion has been closed.