Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to trigger reload #3179

Open
donny26utama opened this issue Oct 10, 2024 · 8 comments
Open

How to trigger reload #3179

donny26utama opened this issue Oct 10, 2024 · 8 comments

Comments

@donny26utama
Copy link

@push('scripts') {{ $dataTable->scripts(attributes: ['type' => 'module']) }} @endpush

I have an ajax action, after complete I want to reload the datatable. how to call datatable ajax reload?

@yajra
Copy link
Owner

yajra commented Oct 11, 2024

Just call the draw event:

LaravelDataTables['table-id'].draw()

@donny26utama
Copy link
Author

I have tried, but LaravelDataTables is undefined

@donny26utama
Copy link
Author

donny26utama commented Oct 14, 2024

here is my code

@push('page-script')
    {{ $dataTable->scripts(attributes: ['type' => 'module']) }}
    <script>
        LaravelDataTables['productcategories-table'].draw();
    </script>
@endpush

@yajra
Copy link
Owner

yajra commented Oct 14, 2024

It seems you're using vite, inline scripts should be mostly a module type. You can also add the document ready if needed.

    <script type="module">
        LaravelDataTables['productcategories-table'].draw();
    </script>

@donny26utama
Copy link
Author

image
I have try your suggestion, but still not work.
image

@donny26utama
Copy link
Author

@yajra please help me

@yajra
Copy link
Owner

yajra commented Oct 23, 2024

I think you need to call the script when dom is ready. The complete script should be something like:

$(function() {
  $('.btn-reload').on('click', function() {
    LaravelDataTables['productcategories-table'].draw();
  });
})

Copy link

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the stale label Nov 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants