Possible bug when using defaults?
Possible bug when using defaults?
mihomes
Posts: 165Questions: 23Answers: 0
I may have come across a bug or perhaps I am looking at this wrong. In the order of their loading :
jquery.dataTables.js - loads datatables
dataTables.bootstrap.js - I am extending some defaults with this for example :
[code]
$.extend( true, $.fn.DataTable.defaults, {
"dom": "<'row'<'col-sm-6'l><'col-sm-6'f>><'row'<'col-md-12 col-sm-12 text-center'r>><'table-scrollable't><'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>",
"pagingType": "bootstrap_full_number",
"language": {
"lengthMenu": "_MENU_ per page",
"search": "Search: _INPUT_",
"emptyTable": "No data available.",
"info": "Showing _START_ to _END_ of _TOTAL_ entries",
"infoEmpty": "Showing 0 to 0 of 0 entries",
"infoFiltered": "(filtered from _MAX_ total entries)",
"processing": ' Please wait...'
},
"lengthMenu": [
[10, 25, 50, 100, 250, -1],
[10+' rows', 25+' rows', 50+' rows', 100+' rows', 250+' rows', "Show All"] // change per page values here
]
} );
[/code]
and finally I load my own options for the datatable in question in another js file such as :
[code]
dt = $('#datatable').DataTable({
"dom": "<'row'<'col-sm-6'l><'col-sm-6'f>><'row'<'col-md-12 col-sm-12 text-center'r>><'row'<'col-sm-12'<'#dtButtons'>>><'table-scrollable't><'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>",
"language": {
"emptyTable": "some custom message for this table"
},
"processing": true,
"serverSide": true,
.............
[/code]
What I expected was the defaults to be loaded then my own options take precedence over those defaults. Instead, only the head of the table shows and nothing else, but with zero errors showing in the console.
I later tried the 'old' format for my defaults :
[code]
$.extend( true, $.fn.dataTable.defaults, {
"dom": "<'row'<'col-sm-6'l><'col-sm-6'f>><'row'<'col-md-12 col-sm-12 text-center'r>><'table-scrollable't><'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>",
"pagingType": "bootstrap_full_number",
"oLanguage": {
"sLengthMenu": "_MENU_ per page",
"sSearch": "Search: _INPUT_",
"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)",
"sProcessing": ' Please wait...'
},
"aLengthMenu": [
[10, 25, 50, 100, 250, -1],
[10+' rows', 25+' rows', 50+' rows', 100+' rows', 250+' rows', "Show All"] // change per page values here
]
} );
[/code]
... and this worked as expected.
jquery.dataTables.js - loads datatables
dataTables.bootstrap.js - I am extending some defaults with this for example :
[code]
$.extend( true, $.fn.DataTable.defaults, {
"dom": "<'row'<'col-sm-6'l><'col-sm-6'f>><'row'<'col-md-12 col-sm-12 text-center'r>><'table-scrollable't><'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>",
"pagingType": "bootstrap_full_number",
"language": {
"lengthMenu": "_MENU_ per page",
"search": "Search: _INPUT_",
"emptyTable": "No data available.",
"info": "Showing _START_ to _END_ of _TOTAL_ entries",
"infoEmpty": "Showing 0 to 0 of 0 entries",
"infoFiltered": "(filtered from _MAX_ total entries)",
"processing": ' Please wait...'
},
"lengthMenu": [
[10, 25, 50, 100, 250, -1],
[10+' rows', 25+' rows', 50+' rows', 100+' rows', 250+' rows', "Show All"] // change per page values here
]
} );
[/code]
and finally I load my own options for the datatable in question in another js file such as :
[code]
dt = $('#datatable').DataTable({
"dom": "<'row'<'col-sm-6'l><'col-sm-6'f>><'row'<'col-md-12 col-sm-12 text-center'r>><'row'<'col-sm-12'<'#dtButtons'>>><'table-scrollable't><'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>",
"language": {
"emptyTable": "some custom message for this table"
},
"processing": true,
"serverSide": true,
.............
[/code]
What I expected was the defaults to be loaded then my own options take precedence over those defaults. Instead, only the head of the table shows and nothing else, but with zero errors showing in the console.
I later tried the 'old' format for my defaults :
[code]
$.extend( true, $.fn.dataTable.defaults, {
"dom": "<'row'<'col-sm-6'l><'col-sm-6'f>><'row'<'col-md-12 col-sm-12 text-center'r>><'table-scrollable't><'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>",
"pagingType": "bootstrap_full_number",
"oLanguage": {
"sLengthMenu": "_MENU_ per page",
"sSearch": "Search: _INPUT_",
"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)",
"sProcessing": ' Please wait...'
},
"aLengthMenu": [
[10, 25, 50, 100, 250, -1],
[10+' rows', 25+' rows', 50+' rows', 100+' rows', 250+' rows', "Show All"] // change per page values here
]
} );
[/code]
... and this worked as expected.
This discussion has been closed.
Replies
That is exactly what should happen. Can you link me to the page showing the error so I can investigate please?
This should be true if you run it on your console: `$.fn.dataTable.defaults === $.fn.DataTable.defaults`
Allan
Unfortunately I can't link to the page as it is in development (domain pw'ed) and it is part of a user login (I would need to setup a user account with examples from the db) for you. Any other ideas or could I send you some files in some way?
Not sure if this will help or not, but here is a debug when it happens - http://debug.datatables.net/aqeser - although I did not see the $.extend from dataTables.bootstrap.js listed.
Allan
This fix appears to completely break table rendering for me.
I'll check back tomorrow after work and if you believe that your fix is good I will try to provide an example then.
Allan
Thanks for the quick fix.
I agree that it now Works For Me.