Closed hemant17 closed 4 years ago
Looking at the source it wouldn't currently be possible to show the index of the current item as a column in the table.
A PR could be made for this however I'm not sure how useful it would be as the whole point of this package is to filter, search & paginate data and the index would change when these functions are performed. Pagination could be overcome by using the pagination 'from' field and adding the current item index. But as soon as you sort/search the data the items would not retain their serial number.
@rappasoft Not sure what the best way to implement this would be; maybe this could be added as a property on the table component?
These requests literally make no sense to me. There is no use for this feature.
I think you can do like this. Feel free to modify:
public function mount()
{
$this->index = $this->page > 1 ? ($this->page - 1) * $this->perPage : 0;
}
public function columns(): array
{
return [
Column::make(__('No.'))->format(fn () => ++$this->index),
//...
];
}
I think you can do like this. Feel free to modify:
public function mount() { $this->index = $this->page > 1 ? ($this->page - 1) * $this->perPage : 0; } public function columns(): array { return [ Column::make(__('No.'))->format(fn () => ++$this->index), //... ]; }
it's showing but when I delete the row with the action button it shows me this error
I think you can do like this. Feel free to modify:
public function mount() { $this->index = $this->page > 1 ? ($this->page - 1) * $this->perPage : 0; } public function columns(): array { return [ Column::make(__('No.'))->format(fn () => ++$this->index), //... ]; }
it's showing but when I delete the row with the action button it shows me this error
Since pagination changes, just declare your index/serial and move implementation to columns
directly:
protected $index = 0;
public function columns(): array
{
$this->index = $this->page > 1 ? ($this->page - 1) * $this->perPage : 0;
return [
Column::make(__('No.'))->format(fn () => ++$this->index),
//...
];
}
The easy way, just add to your view (e.g. row.blade.php
):
<x-livewire-tables::bs5.table.cell>
{{ ($this->page > 1 ? ($this->page - 1) * $this->perPage : 0) + $loop->iteration }}
</x-livewire-tables::bs5.table.cell>
I think you can do like this. Feel free to modify:
public function mount() { $this->index = $this->page > 1 ? ($this->page - 1) * $this->perPage : 0; } public function columns(): array { return [ Column::make(__('No.'))->format(fn () => ++$this->index), //... ]; }
it's showing but when I delete the row with the action button it shows me this error
Since pagination changes, just declare your index/serial and move implementation to
columns
directly:protected $index = 0; public function columns(): array { $this->index = $this->page > 1 ? ($this->page - 1) * $this->perPage : 0; return [ Column::make(__('No.'))->format(fn () => ++$this->index), //... ]; }
why in version 3 $this->page not found?
in version 3 user $this->getPage()
i make traits for numbering
namespace App\Traits\Livewire;
use Rappasoft\LaravelLivewireTables\Views\Column;
trait WithTableNumbering
{
protected int $index = 0;
public function numberingColumn(): Column
{
return Column::make(__('No.'))
->label(function () {
$this->initializeIndex();
return ++$this->index;
});
}
protected function initializeIndex(): void
{
if ($this->index === 0) {
$this->index = $this->getPage() > 1 ? ($this->getPage() - 1) * $this->perPage : 0;
}
}
}
and in livewire datatables
use App\Traits\Livewire\WithTableNumbering;
class UsersTable extends DataTableComponent
{
use WithTableNumbering;
protected $model = User::class;
public function columns(): array
{
return [
$this->numberingColumn()
->sortable(),
.....
];
}
}
able data is for multiple users and multiple users are interesting the data in the database but when you show it to the user to look like 5,56,64 more like that which is not good so I want to show them like the 1,2,3