action callbacks inside collection buttons not triggered and enabled: false ignored on nested button
action callbacks inside collection buttons not triggered and enabled: false ignored on nested button

Hi,
I’m using DataTables v2 with the new layout.buttons configuration. I have a collection button with child buttons inside it. The problem is twofold:
The child buttons inside the collection render correctly in the dropdown, but clicking them does not trigger their action callbacks at all.
Setting enabled: false on these nested child buttons does not disable them on initialization as expected; they appear enabled.
Here is a minimal example showing the issue:
https://jsfiddle.net/24s0dvrz/
Questions:
Is this a bug or known limitation of DataTables v2 when using layout.buttons with collection buttons?
Should the action callbacks work on nested buttons as usual?
Should enabled: false disable nested buttons on initialization?
Thanks in advance for any clarification.
Answers
The action isn't being called because the collection buttons never become enabled. The
button-selector
you are using, ieactionsCollection.withdrawBtn:name
, is not correct and won't select any button to enable/disable. You only need to provide the specific buttons name, for examplewithdrawBtn:name
. Use this instead:Updated test case:
https://jsfiddle.net/47v1gywL/2/
I added the datatables.css and buttons.css to show the styling of the buttons to see if they are enabled.
Kevin
You have
enable: false,
on the top level button but it should beI commented out these lines so you can see the
buttons.buttons.enabled
does work on the collection buttons:https://jsfiddle.net/wrstL0e9/
Click Actions without selecting a row to see the disabled collection buttons.
Kevin
Makes perfect sense. Maybe i have some problems with loading datatables.
You probably will have done yesterday, but things should be back to normal now. Does the CDN link you are using load okay for you? It is loading here, but there are some reports of caching errors that are taking a little while to clear.
Allan
everything is loading correctly. Maybe the problem have something to do with loading data from ajax call
What exactly is the problem?
What troubleshooting steps have you taken?
Can you post a link to your page so we can help debug?
Kevin
On a test scenario where i bind the table from html it works. But when i use serverSide with ajax the same setup does not work. I tried to call collectionRebuild on initComplete and add all buttons then but still not luck with action fire.
Here is my code
$(function () {
bindInvoicesTable();
})
When I comment adding of button (actionsCollection) and comment out the commented code it works
I don't see anything obvious. That's a lot of code to try debugging just by looking at it. We will need a test case to trace through the code. If you can't post a link to your page or send the link privately to Allan then please build a test case the replicates the issue. You can get a server side processing template to start with here.
Kevin
I had a few minutes so I built a test case with your above code:
https://live.datatables.net/yaroyala/122/edit
Made some modifications for it to work in the JS Bin environment. I added
select: true
to get theselected
class. Not sure if you are using this but it wasn't in your code. Commented out the language stuff as it doesn't pertain to the issue.The first thing I noticed is the
click
event wasn't firing. In my test case the HTML table is defined like this:Notice no
tbody
so the click event selector of$('#invoicesTable tbody').on('click', 'tr'
won't work since thetbody
doesn't exist in the document when the click event is instantiated. I changed the selector to this:Now the click event fires and the code to enable/disable the buttons now works. I suggest doing some debugging to see if the click event is working in your environment. If not make the same change I made. Is this your issue?
If this doesn't solve the issue then please update my test case to show the problem.
Kevin
My table is defined like this
The event you mentioned is trigger each time i click on a row. Still buttons in the collection do not fire the action. I am starting to think that this have something with bootstrap 5 styling of the table.
I removed the select extension and used the Download Builder to create a Bootstrap 5 environment. I changed the click event selector back to what you have and added the
tbody
tag.https://live.datatables.net/yaroyala/124/edit
The code still seems to work correctly. Clicking the row enables the collection buttons.
Did you include the Datatables Bootstrap integration files for the version you are using? Use the Download Builder for this.
Have you stepped through the event handler code to make sure it's doing what you expect?
I think to further troubleshoot we will need to see a link to your page or test case that replicates the issue.
Kevin
Is the problem that the buttons aren't being enabled or that the action function isn't executing or executing as expected. If the latter check the console for errors when clicking the button.
Kevin