yajra/laravel-datatables-html

rowID doesn't seem to work

csb346 opened this issue · 3 comments

hi!

I have a datatable updated by ajax and now need to use the select feature. Easy to implement as described on documentation.
Unfortunately i can't get the "retain selection on reload" to work as it is described on datatables example: https://datatables.net/extensions/select/examples/initialisation/reload.html

I would like to be able to select multiple lines through table pages as in the example, and then add a "select all" button two (but it will be the next step) to perform actions on selected rows.

Here is my builder code:

$builder->columns([
            ['data' => 'id', 'title' => 'id'],
            ['data' => 'email', 'title' => 'Email'],
            ['data' => 'active', 'title' => 'Active'],
        ]);
        $builder->addAction([
            'defaultContent' => '',
            'data'           => 'action',
            'name'           => 'action',
            'title'          => 'Action',
            'render'         => null,
            'orderable'      => false,
            'searchable'     => false,
            'exportable'     => false,
        ]);
        $builder->parameters([
            'responsive' => true,
            'searching' => true,
            'select' => [
                'style' => 'multi',
                'className' => 'selected',
                'selector' => 'td:not(:last-child)',
            ],
            'deferRender' => true,
            'rowId' => 'id,
        ]);
        $builder->ajax([
            'url' => route('admin.projectusers.datatable'),
            'type' => 'GET',
        ]);

For testing purposes I have the "id" column visible, but the final result should be without that column but being able to identify the user id of each selected row.

Any Idea?

  • Debian 9
  • PHP 7.2
  • Laravel 5.7
  • laravel-datatables-oracle v8.13.6
yajra commented

You need to have a variable that tracks the selected column. I think that example only works on the current page loaded. See https://datatables.net/examples/server_side/select_rows.html for ref.

Why doesn't this simply work with the select plugin?

https://www.gyrocode.com/projects/jquery-datatables-checkboxes/examples/data-sources/server-side/

I am very confused. Almost all of the guides say that it should automatically work with the rowId option.

yajra commented

That will only select the visible columns. The problem is if you still want to track the selected rows that was previously selected from the other page thus the need to a tracker variable to store the selections.