click event to the ColVis list items execute multiple times
click event to the ColVis list items execute multiple times

Need to add a click event to the ColVis list items.
$('.ColVis_collection li').click(function () {
alert($(this).text());
});
Working good. Pasted the code in drawCallback function
drawCallback: function () {
$('.ColVis_collection li').click(function () {
alert($(this).text());
});
}
this function only works while paste that inside drawCallback function. Problem is click function get execute multiple times for a single click. Kindly do help ASAP
This discussion has been closed.
Answers
Hi @Gurupriyan ,
drawCallback
is called on every table draw - this means you're adding an additionalclick
listener every time the table is drawn, which is why you're seeing multiple messages (which will increase with every draw).If it's working good, what was the intention of putting it into the callback function?
Cheers,
Colin
Thanks @colin .
The above function only get works if we paste inside the drawCallback function . Otherwise not working. Thats why i put inside drawCallback function
One thing you could try is to to use
on
andoff
, rather than click - something likeIf that doesn't help, we'd need to see the problem. 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
Thanks again @colin . But this not works. Its killing click event. And Sorry to say that my code need to be confidential as per my organization policy. So unfortunately can't share the code for test case with you. Cheers
I would put that code in
initComplete
.For this issue we don't need to see your data. We just need to see a page that has enough of your configuration running to see the click event. You can simulate a small amount of data.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin