Globally change default oLanguage

Globally change default oLanguage

dwbiz05dwbiz05 Posts: 7Questions: 0Answers: 0
edited February 2013 in General
I'm trying to globally change the filtering info for all datatable instances without having to edit each one.

I was trying this:

[code]
$.extend( $.fn.dataTable.defaults, {
"oLanguage": {
"sInfoFiltered": "(filtered from _MAX_ total entries)"
}
});
[/code]

but I can't seem to get it to work...

Any thoughts?

Dave

Replies

  • dwbiz05dwbiz05 Posts: 7Questions: 0Answers: 0
    FYI,

    I found that placing this code in my main page does the trick. Any reason why I shouldn't use this?

    [code]
    $.fn.dataTable.defaults.oLanguage.sInfoFiltered = "";
    [/code]

    Thanks,

    Dave
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Hi Dave,

    No reason why you shouldn't use the second one. The reason the first one doesn't work is that $.extend is shallow by default, so you are replacing all of `oLanguage` in the defaults with the object you define there (i.e. it removes all the other strings)!. You would need a deep copy:

    [code]
    $.extend( true, $.fn.dataTable.defaults, {
    "oLanguage": {
    "sInfoFiltered": "(filtered from _MAX_ total entries)"
    }
    });
    [/code]

    Allan
This discussion has been closed.