Overriding default layout
Overriding default layout
Link to test case:
https://live.datatables.net/segonewe/1/edit?js,output
Description of problem:
I'm trying to upgrade a large application from v1.10 to v2.1.4, and replace the use of the deprecated dom
option with the new layout
option.
I've managed to get quite close, but I've run into a strange problem.
I have a default layout which adds a custom feature in the top and bottom. On some pages, I need to override that default layout with a custom layout. But trying to do so results in a weird mix of the two!
Eg:
Default layout:
top: {
features: [
{
pageLength: {}
},
{
div: {
text: "(custom feature)"
}
},
{
search: {
placeholder: "Search"
}
}
]
}
Overridden layout:
top: {
features: [
{
pageLength: {}
},
{
div: {
text: "(custom feature 1)"
}
},
{
div: {
text: "(custom feature 2)"
}
},
{
search: {
placeholder: "Search"
}
}
]
}
Expected result:
* Page length
* Custom feature 1
* Custom feature 2
* Search
Actual result:
* Page length
* Custom feature 1
* Search
* Custom feature 2
* Search
Why am I getting an extra "search" feature injected into the layout? Is there an easy way to fix this?
This question has an accepted answers - jump to answer
Answers
I think I've found a rather hacky workaround: rather than using
top
in the page-specific setup, I settop
tonull
and usetop1
instead.I'm guessing there's a bug somewhere in the code to merge the table settings with the default settings.
That's an interesting one - thanks for posting this. The issue is that the defaults are merged with the per table options as a deep merge - not a shallow one. In this case you what a shallow copy of the position attributes.
I need to have a bit of a think about this, as there are cases where one might want (and expect) a deep copy.
For the moment, your workaround is a good one.
Allan