Description
In the laravel-datatables-vite
repository, I found an interesting ajax batch feature that is supposed to be used by creating a button like this:
Button::make('ajaxBatch')
->text('Restore')
->url(route('batch-restore-action-url'))
->confirmation('Generic confirmation message.') // Optional if you want confirmation before proceeding.
->onCancel('function(response) { alert("confirmation cancelled") }')
->onSuccess('function(response) { alert("success") }')
->onError('function(err) { alert("error") }')
Unfortunately, if I try to use it in my Datatable class, this mails with the following error:
Method Yajra\DataTables\Html\Button::url does not exist.
I cannot find any reference of any of those methods in Laravel Datatables.
Did I miss something?
Metadata
Metadata
Assignees
Labels
No labels
Activity
[-]Batch action not working?[/-][+]Ajax batch action not working?[/+]yajra commentedon Nov 6, 2024
Thanks for reporting, it appears that the magic method from the Fluent class breaks when the Macroable trait was added via: yajra/laravel-datatables-html#224
I tried to play with that script and this is the workaround for now:
ajaxBatch.js
script.yajra commentedon Nov 6, 2024
A better approach would be like the below to pass the static analysis (phpstan):
Seb33300 commentedon Nov 6, 2024
Thanks, I will take a look on this.
FYI, I also noticed that
laravel-datatables-vite
still has dependencies on Datatables v1:https://github.com/yajra/laravel-datatables-vite/blob/51a126ec6020b7f3b97715e3e08af07c5be4f781/package.json#L33-L36
But from the documentation, we can read Datatables v2 is required:
https://yajrabox.com/docs/laravel-datatables/11.0#requirements
I had to load Datatables v2 by myself instead of importing
laravel-datatables-vite
as documented:https://yajrabox.com/docs/laravel-datatables/11.0/quick-starter#datatables-with-vite
yajra commentedon Nov 6, 2024
DataTables v1 should work fine. You'll need v2 if you want to use the new layout function.
But yeah, the vite package should be updated to allow v2. Please feel free to submit a PR if possible. Thanks!
Marcoable
trait usage together withFluent
helper yajra/laravel-datatables-html#227