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

[QUESTION]: Assign datatable to js variable so table can be reload? #1289

Open
servitux opened this issue Jun 21, 2024 · 1 comment
Open
Labels
question Just a question, not an issue or bug

Comments

@servitux
Copy link

servitux commented Jun 21, 2024

In file datatable.blade.php change

@push('js')
<script>
    $(() => {
        $('#{{ $id }}').DataTable( @json($config) );
    })
</script>
@endpush

to

@push('js')
<script>
        var {{ $id }} = $('#{{ $id }}').DataTable( @json($config) );
</script>
@endpush

so you can do

table1.ajax.reload(null,false);

in your blade without reloading all page

@servitux servitux added the enhancement Improvement related to this package label Jun 21, 2024
@dfsmania
Copy link
Collaborator

Hi @servitux , after the Datatables initialization, you can access the table with:

var myTable = $('#id-of-target-datatable').DataTable();

where #id-of-target-datatable refers to the ID of the target datatable element, the one you usually set through the id property of the component.

@dfsmania dfsmania added question Just a question, not an issue or bug and removed enhancement Improvement related to this package labels Jun 24, 2024
@dfsmania dfsmania changed the title [FEATURE] assign datatable to js variable so table can be reload [QUESTION]: Assign datatable to js variable so table can be reload? Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Just a question, not an issue or bug
Projects
None yet
Development

No branches or pull requests

2 participants