Datatable 1.9 - defaults and language

Datatable 1.9 - defaults and language

matthiasmatthias Posts: 1Questions: 0Answers: 0
edited February 2012 in General
Hi,
I try to use the 'Setting defaults' to set the 'oLanguage' option.

If I set the parameters by keywords it raises a JS error: A is undefined (see http://jsfiddle.net/matthias/hBnWt/)

If I set the parameter with the 'sUrl'... it's not formating at all :-( (see http://jsfiddle.net/matthias/b7huv/)

Without the parameter it's behaving normally (see http://jsfiddle.net/matthias/QLfmB/)

Help is very much appreciated...

BTW: great product... the beer will follow ;-)

Regards,
Matthias

Replies

  • allanallan Posts: 63,397Questions: 1Answers: 10,451 Site admin
    Hi Matthias,

    Thanks for posting a link to JS Fiddle with your test case - really useful!

    The problem is this line:

    [code]
    $.extend( $.fn.dataTable.defaults, {
    [/code]

    It is only shallow copying - so in fact your oLanguage object is completely replacing the DataTables default one, and since your oLanguage object doesn't define every language option (the ARIA ones for example), then they aren't present in the language object DataTables sees.

    So what you need to do is a deep copy:

    [code]
    $.extend( true, $.fn.dataTable.defaults, {
    [/code]

    and that will do the job :-)

    Regards,
    Allan
  • rpiresrpires Posts: 2Questions: 0Answers: 0
    edited March 2012
    Hello,

    I'm having the same problem, even adding the "true" parameter it still doesn't work, the defaults are simply ignored.

    Any help is appreciated, thank you!


    [code]$.extend(true, $.fn.dataTable.defaults, {
    "sPaginationType": "full_numbers" //IT'S IGNORED :( PAGINATION TYPE IS NOT APPLIED
    });
    [/code]

    [code]
    $("table.datatable").dataTable({
    "bServerSide": true,
    "sAjaxSource": '@Url.Action("GetGridData")',
    "fnServerData": function (sSource, aoData, fnCallback) {
    $.ajax({
    "dataType": 'json',
    "type": "POST",
    "url": sSource,
    "data": aoData,
    "success": fnCallback
    });
    },
    "bLengthChange": false,
    "aoColumns": [
    { "sName": "Id", "sType": 'numeric' },
    { "sName": "Name" }
    ]
    });
    [/code]
  • rpiresrpires Posts: 2Questions: 0Answers: 0
    Detail: I'm using datatable version 1.8.1.

    Wondering if setting defaults doesn't work in that version...
  • allanallan Posts: 63,397Questions: 1Answers: 10,451 Site admin
    Correct - defaults are new in 1.9: http://datatables.net/new/1.9

    Allan
This discussion has been closed.