livewire-datatables icon indicating copy to clipboard operation
livewire-datatables copied to clipboard

how to show row number as a column serial number in livewire datatable

Open salman-bft opened this issue 2 years ago • 3 comments

how to show row number as a column serial number in livewire datatable

Column::name('id')->label('Id')->truncate(40),

i want to show serial number instead of id

salman-bft avatar Jul 20 '23 07:07 salman-bft

What are you trying to archive?

To have your table-header called "serial number" or you try to get the sql column "serial number" both could be achived. Or you could hide the "id" column and show the "serial number" as the first column.

m4tr1ck avatar Jul 25 '23 11:07 m4tr1ck

i want to hide the "id" column and show the "serial number" as the first column.

salman-bft avatar Jul 26 '23 08:07 salman-bft

You could use something like this:

class Table extends LivewireDatatable
{
    public $hideable = 'select';
    public $sort = "serial_number|asc";
    public $model = Model::class;
    public function builder()
    {
        return Model::query();
    }

    public function columns()
    {
        return [
            NumberColumn::name('id')
                  ->hide(),
            Column::name('serial_number'),
        ];
    }
}

You can define the order and what will be visible in the tables. The ID Column could also be removed and the table is still working.

m4tr1ck avatar Jul 28 '23 05:07 m4tr1ck