F
Filament11mo ago
Daniel

Can't reorder table rows

When trying to reorder table rows in a RelationManager values in order_column DB do change but the rows are always jumping back to their initial position. I've activated reordering on the table like that:
->reorderable('order_column')
->defaultSort('order_column')
->reorderable('order_column')
->defaultSort('order_column')
Here's a short screen capture:
5 Replies
Homd
Homd11mo ago
Can I see your model.php? are you trying use eloquent-sortable package?
Homd
Homd11mo ago
GitHub
GitHub - spatie/eloquent-sortable: Sortable behaviour for Eloquent ...
Sortable behaviour for Eloquent models. Contribute to spatie/eloquent-sortable development by creating an account on GitHub.
Daniel
Daniel11mo ago
Yeah, I'm using this package and my model looks like that:
<?php

use Illuminate\Database\Eloquent\Model;
use Spatie\EloquentSortable\Sortable;
use Spatie\EloquentSortable\SortableTrait;

class MyModel extends Model implements Sortable
{
use SortableTrait;

protected $fillable = [
'order_column',
];
}
<?php

use Illuminate\Database\Eloquent\Model;
use Spatie\EloquentSortable\Sortable;
use Spatie\EloquentSortable\SortableTrait;

class MyModel extends Model implements Sortable
{
use SortableTrait;

protected $fillable = [
'order_column',
];
}
Homd
Homd11mo ago
That seems ok. Is the name of your column really 'order_column' or was it something else? Mine works well with this: resource
return $table
->columns([
Tables\Columns\ImageColumn::make('img_url'),
Tables\Columns\TextColumn::make('name'),
Tables\Columns\TextColumn::make('description')->wrap()->html(),
])
->reorderable('order_number')
->defaultSort('order_number')
return $table
->columns([
Tables\Columns\ImageColumn::make('img_url'),
Tables\Columns\TextColumn::make('name'),
Tables\Columns\TextColumn::make('description')->wrap()->html(),
])
->reorderable('order_number')
->defaultSort('order_number')
model
class Level extends Model implements Sortable
{
/**
* @var array
*/
protected $fillable = ['name', 'img_url', 'description', 'order_number', 'created_at', 'updated_at'];
use SortableTrait;
}
class Level extends Model implements Sortable
{
/**
* @var array
*/
protected $fillable = ['name', 'img_url', 'description', 'order_number', 'created_at', 'updated_at'];
use SortableTrait;
}
Daniel
Daniel11mo ago
Yes, the name is order_column and as already mentioned it does change in the DB when reordering. Did you also have this in a RelationManager?