Force row 'selected' after inline edit
Force row 'selected' after inline edit
I have a page with 2 datatables in a parent-child relationship.
On clicking a row in the parent table, its child rows are displayed in the other table.
The parent table uses persistent checkboxes, which when clicked, will toggle the state of the selected row
Can I 'prevent this toggle, or re-select the parent row after its edit, so the child rows are displayed, (otherwise they disappear on editing the parent) ?
Thanks
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
You should be able to use
event.stopPropagation()
on the click handler for the checkbox. See MDN docs.The other option is to use the
sRowSelector
option of TableTools to modify the selector for the row, like in the inline example.I've just put a little example of this together here.
It is greatly simplified, but that is good to show what is happening I think. The first event handler just does a class toggle so you can see when something happens from it.
The second is an event handler on the checkboxes and it stops the click event from bubbling up through to the row click handler.
If you comment out the
e.stopPropagation()
call you will see the click going "through" to the row.Regards,
Allan
I added the code as you suggested, but it doesn't stop the selected row toggle.
Can't easily provide a working sample unless i send you a PM, but here is the js snippet from the page...
Hi,
If you would be able to send me a PM so I can debug the issue directly, that would be useful.
Thanks,
Allan
OK, PM sent
Awesome - thanks!
So to get it working the way you want use:
The difference is in the
tbody
part I've added.Now the reason for that is how jQuery works with delegated events. It actually adds a click listener on the element(s) given by the main selector and then when a click occurs it filters them by the delegate selector and decides if they should be triggered or not.
The reason it wasn't working before was that the TableTools click was being executed before this one, so we couldn't cancel the TableTools one (it had already happened!).
Making it more selective means that the new event will occur first, and thus give us the ability to stop the other event handlers happening after it.
Hope that makes sense :-)
Allan
It does make sense, and it works !
Cheers Allan