Button inside Jquery Datatables with x-on:click fire three times in a row. #723
edy-tanto
started this conversation in
4. General
Replies: 1 comment 1 reply
-
You can defer Alpine with some code, and initialize Datatables in there. It's using an undocumented feature so know that it can change in the future without warning (or just constrain your Alpine version). const alpine = window.deferLoadingAlpine || ((alpine) => alpine())
window.deferLoadingAlpine = function (callback) {
alpine(callback)
$( "#the-table" ).DataTable()
} it needs to run before you load in the Alpine script, see here: |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Link to test case:
https://codepen.io/ed_tanto/pen/abNpbQv?editors=1111
Description of problem:
I try to implement datatables inside Alpine JS component, I create a button for each row and add event listener using "x-on:click". The problem happen when I try to click the button, it fires the method three times. I try to dive into what happen and the clue I got is related with Datatables Orthogonal Data (my assumption because datatables render multiple source of data and create multiple buttons too), I also manually set the data-search, data-filter, data-sort but doesn't seem to make any effect. I also try to use "onclick" as event listeners and it works fine (only fire once for each click).
So, is there any clues what actually happen with datatables and Alpine?
Thank you all
Beta Was this translation helpful? Give feedback.
All reactions