How can I set a language file as default?

How can I set a language file as default?

shaggy73shaggy73 Posts: 5Questions: 2Answers: 1

Actually I tried this, but it doesn't work:

    $.extend($.fn.dataTable.defaults, {
        language: { url: "/Scripts/dataTables.german.json" }
    });

It does not even make an call to the file when building the table. If I set the file the same way during initialization of a certain table, it works. But it would be much more convenient, if I could set it as default.

Answers

  • colincolin Posts: 15,118Questions: 1Answers: 2,583

    Yep, you need to set it on each table - see here.

    Colin

  • shaggy73shaggy73 Posts: 5Questions: 2Answers: 1

    Too bad. That's actually not what I wanted to hear :)
    Is there a good reason, why I can set things like searching and ordering as default, but not the language file?

  • kthorngrenkthorngren Posts: 20,145Questions: 26Answers: 4,736

    Using $.fn.dataTable.defaults works here:
    http://live.datatables.net/fumojapu/1/edit

    Have you checked for errors? Maybe the URL is incorrect?

    Kevin

  • colincolin Posts: 15,118Questions: 1Answers: 2,583

    Ah nice, thank you for correcting me there, Kevin,

    Colin

  • shaggy73shaggy73 Posts: 5Questions: 2Answers: 1

    Ok, again my fault... What I basically did was something like this;

    $(document).ready( function () {
      $.extend($.fn.dataTable.defaults, {
        language: { url: "https://cdn.datatables.net/plug-ins/1.10.20/i18n/German.json" }
      });
    } );
    
    var table = $('#example').DataTable();
    

    Means, setting the default inside the "docuent ready", and the initialization of the data table outside - which leads to first creating the table and then setting defaults. Of course this does not work.

    Sorry.

This discussion has been closed.