Perent / Child - disable child New Button
Perent / Child - disable child New Button

I have a number of Parent/Child screens in our application. As is normal, when a parent record is selected, the child table is populated.
But we have a logic problem. If no parent record is selected, the child tables "New" button is still active. Choosing this will get an error when it gets to the server.
Is there a way to disable the child table's "New" button unless a parent record is selected?
This question has accepted answers - jump to:
This discussion has been closed.
Answers
I just noticed that the example
https://editor.datatables.net/examples/advanced/parentChild.html
has the same issue.
The child's "New" button appears to work, as the ensuing modal has the "Location" field. However, it doesn't actually add the new record.
Looks like an error. Either enable the new child record, or don't show the child's buttons until a parent location is selected.
I would look at using the
draw
event for the child table. In the event usepage.info()
to see if the table has any rows. The use thebuttons().enable()
API to enable or disable the button.Kevin
Kevin's suggestion is one way to go. Another, which would be better if there are more rows in the user's table would be the following:
I've updated the example, which will make its way to the site on the next build - probably in the next week.
Thanks to all for the suggestions and steps to reproduce,
Colin
Cool, I've never used
buttons.buttons.init
. Got my learning in for the dayKevin
And it's barely breakfast - might as well go back to bed, the day can't get any better