Custom checkbox in header

Hi, I’ve added a checkbox in the header section like this:

mygrid.attachHeader(" ,<input type='checkbox' id='checkbox'>, ");

But I can’t get the checkbox to work with my code.

$("#checkbox").change(function() { if(this.checked) { alert("checked"); }else{ alert("unchecked"); } });

If I put the checkbox outside of the header it works fine.

Is there a way to fix this? Or am I not meant to put custom code in header? I’ve also noted that if I click the current checkbox it sorts the column which I don’t want.

Thank you.

There’s really no way to achieve this? :frowning:

Please, make sure that you attach the event after the init of the grid.

The following code works well for us:

document.getElementById("checkbox").onchange=function() { if(this.checked) { alert("checked"); }else{ alert("unchecked"); } };

Thank you. At least I understand why it wasn’t working now.

It is called after the init() method, but still no luck. Adding a timeout before loading the function resolved the problem though. Thank you!