1

I have a data collection and I have added a column with index:

BACKEND:


Route::get('user-data', function() {
    $model = App\User::query();

    return DataTables::eloquent($model)
                ->addIndexColumn()
                ->toJson();
});

Frontend:

              { data: 'DT_RowIndex', 'orderable': false, 'searchable': false },
              { data: 'name' },
              { data: 'email' },
              { data: 'phone' }
          ]

It gives a perfect result, but I need to keep the index when I filter the table by name.

For example if Mr. Smith is the number four in the list, when I search him datatables hides the other results that don't match and gives him number 1. I need it to keep number 4.

JMP
  • 4,417
  • 17
  • 30
  • 41
Escudo Bravo
  • 75
  • 2
  • 10
  • I think you have an `id` column on your table, you can use that here. `data: 'id'` instead of `data: 'DT_RowIndex'` – STA Oct 26 '20 at 14:15
  • No, I don't have the id column, because ids are very different from index. I need to use index. – Escudo Bravo Oct 26 '20 at 14:26

0 Answers0