Problem when using dataTables defaults together with button.add API
Problem when using dataTables defaults together with button.add API
I don't know when this stopped working, but we had it running for a year in one page.
the settings in datatables.default
$.extend($.fn.dataTable.defaults, {
....
searchBuilder: {
grayscale: false
},
....
} );
Buttons added that activated the extensions:
searchAppTable.button().add(null, {
extend: 'searchBuilder',
grayscale: false,
className: 'btn-secondary',
config: {
depthLimit: 3,
columns: [1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 27, 28, 30, 31, 32, 33, 34, 35, 36, 37, 38]
}
});
This now not working for searchbuilder with the latest versions of dataTables and relevant extensions.
However if the default section for searchBuilder is removed from defaults, the button.add API works again...
$.extend($.fn.dataTable.defaults, {
....
/* searchBuilder: {
grayscale: false
}, */
....
} );
We were not depending on the defaults for searchBuilder so we just removed it, so this is really a FYI for anyone experience the same.
KR,
Björn Hasselberg
This question has accepted answers - jump to:
Answers
I built a test case for you to test it and you are right it fails with this error:
Test case:
https://live.datatables.net/dijodeva/1/edit
Kevin
Thanks Kevin
You'll need to use:
In this case, to do a deep extend. Otherwise you replace the default
searchBuilderobject with one that just has that single property.Allan
That did not fix the testcase @allan ?
YEs the same error occurs, updated test case:
https://live.datatables.net/dijodeva/3/edit
Kevin
Ah sorry. I'm on a mobile at the moment and the live site doesn't play nicely with it. I'll take a look tomorrow on a proper computer
.
Allan
https://live.datatables.net/dijodeva/4/edit
Couple of things going on:
greyscalerather thangrayscale. Apologies - for parameters I normally follow American English in keeping with JS and CSS, but that one slipped by! I'll look at putting in an alias.DataTable.SearchBuilder.defaults(or$.fn.dataTable.SearchBuilder.defaultsif you prefer - it is the same object).What was causing an issue with setting it on
DataTable.defaults.searchBuilderis the initialisation code:It will take either the options from the init object, or the default initialisation value (that's an important distinction - the there are really three layers here - the init options, the default init option and the default!). It doesn't attempt to merge them, and doing so might actually be a bit tricky since they can easy take multiple type values.
I'll look into making that easier, or at least documenting it and looking at the rest of the extensions, as it took me looking at the code to understand it, so it isn't quite right! For now, set SearchBuilder default values on its own defaults object.
Thanks for posting this!
Allan
Verified and implmented in our test environment, thanks