Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
salman-bft opened this issue Jul 20, 2023 · 3 comments
Open

Comments

@salman-bft
Copy link

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
Copy link

m4tr1ck commented Jul 25, 2023

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
Copy link
Author

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

@m4tr1ck
Copy link

m4tr1ck commented Jul 28, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants