MedicOneSystems / livewire-datatables

Advanced datatables using Laravel, Livewire, Tailwind CSS and Alpine JS
https://livewire-datatables.com/
MIT License
1.19k stars 258 forks source link

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

Open salman-bft opened 12 months ago

salman-bft commented 12 months ago

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

m4tr1ck commented 11 months ago

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.

salman-bft commented 11 months ago

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

m4tr1ck commented 11 months ago

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.