cells().every() addEventListener bug / context loss?
cells().every() addEventListener bug / context loss?
Timmeehhh
Posts: 4Questions: 3Answers: 0
Debugger code (debug.datatables.net):
datatableFoo.cells().every( function () {
if ( this.index().column === 1 ){
this.node().addEventListener('keydown', function(e) {
if (e.key === "Enter") {
console.info("Enter");
}
});
}
} );
Description of problem: Will also "Enter-keydown"-trigger on non-column-index-1 cells... why?
This question has an accepted answers - jump to answer
Answers
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
I pasted your code snippet into this example and it seems to only add the listener to the calls in column 1.
http://live.datatables.net/gezoboke/1/edit
Instead of looping all the cells you could do something like this to limit to just column 1:
See the
cells()
docs for all the options of choosing which cells are returned.If you still need help please update the test case or provide a link to a page replicating the issue so we can help debug.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin