Another solution to the aasort initialisation issues (Firefox creating extra TextNodes)
Another solution to the aasort initialisation issues (Firefox creating extra TextNodes)
NCunningham
Posts: 1Questions: 0Answers: 0
Hi all.
I had problems last night with getting DataTables to work; I was getting the very common
[code]
oColumn.asSorting is undefined
[/code]
error. In my code, I was generating the table from ajax prior to initialising the DataTables plugin (yeah, perhaps not the best way, but I was just focusing on getting it working for a start). What I discovered was that when I add the table header fields, Firefox is sticking extra TextNodes in there. Then, when DataTables attempts to walk the tree, it can't find the headings and no columns are set up, resulting in the above error.
The solution I used was to apply this little snippet:
[code]
const notWhitespace = /\S/;
function cleanWhitespace(node) {
for (var x = 0; x < node.childNodes.length; x++) {
var childNode = node.childNodes[x]
if ((childNode.nodeType == 3)&&(!notWhitespace.test(childNode.nodeValue))) {
// that is, if it's a whitespace text node
node.removeChild(node.childNodes[x])
x--
}
if (childNode.nodeType == 1) {
// elements can have text child nodes of their own
cleanWhitespace(childNode)
}
}
}
[/code]
(Found here: http://www.boonex.com/forums/topic/collapsable-blocks.htm)
Now that it's not 11.30pm, I've clicked to the fact that it would probably be better to start with all the headings defined in the html and remove the ones I don't want (debugging data columns). Nevertheless, I though I'd post this as I didn't see anyone else having diagnosed the issue in this way.
Regards,
Nigel
I had problems last night with getting DataTables to work; I was getting the very common
[code]
oColumn.asSorting is undefined
[/code]
error. In my code, I was generating the table from ajax prior to initialising the DataTables plugin (yeah, perhaps not the best way, but I was just focusing on getting it working for a start). What I discovered was that when I add the table header fields, Firefox is sticking extra TextNodes in there. Then, when DataTables attempts to walk the tree, it can't find the headings and no columns are set up, resulting in the above error.
The solution I used was to apply this little snippet:
[code]
const notWhitespace = /\S/;
function cleanWhitespace(node) {
for (var x = 0; x < node.childNodes.length; x++) {
var childNode = node.childNodes[x]
if ((childNode.nodeType == 3)&&(!notWhitespace.test(childNode.nodeValue))) {
// that is, if it's a whitespace text node
node.removeChild(node.childNodes[x])
x--
}
if (childNode.nodeType == 1) {
// elements can have text child nodes of their own
cleanWhitespace(childNode)
}
}
}
[/code]
(Found here: http://www.boonex.com/forums/topic/collapsable-blocks.htm)
Now that it's not 11.30pm, I've clicked to the fact that it would probably be better to start with all the headings defined in the html and remove the ones I don't want (debugging data columns). Nevertheless, I though I'd post this as I didn't see anyone else having diagnosed the issue in this way.
Regards,
Nigel
This discussion has been closed.