jeroennoten / Laravel-AdminLTE

Easy AdminLTE integration with Laravel
MIT License
3.78k stars 1.08k forks source link

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

Closed servitux closed 1 week ago

servitux commented 3 weeks ago

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

dfsmania commented 3 weeks ago

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 commented 1 week ago

Closed, answer given and no feedback provided!