What is a proper way to have sorted list together with reorderable action?
I want to display sorted table by
order_to_display
column and also have a possibility to reorder table items. The problem is that during reorder action orderBy
gets duplicated, e.g. where `categories`.`menu_id` = 1 order by `products`.`order_to_display` asc, `products`.`order_to_display` asc,
. What is a proper way and how to prevent duplicate of orderBy?
19 Replies
Use
->defaultSort()
instead of setting it inside getEloquentQuery()
Yeh this works.
One more related question.
I have the following table query with a join and both
categories
and products
tables have order_to_display
column.
So in order to overcome ambiguous column error when starting reorder I need to define my reorder column as this: ->reorderable('products.order_to_display')
, reorder loads but when I try to reorder items I get Add [products.order_to_display] to fillable property to allow mass assignment on [App\Models\Product].
but Model has protected $guarded = [];
.
I guess update field should not be with a table prefix. Is there a solution to this? @Dennis KochDo you need both
order_to_display
? Select one or alias the other one.In a query, yes I need to prefix with a table, otherwise MySQL does not know if I want to order by column found in products or categories table because of JOIN.
You can still add an alias on
->select()
right?->select([
...Arr::prependValuesWith([
'id',
'title',
'image',
'price',
'status'
], 'products.'),
'categories.title as category_title'
])
yes I am removing any of columns
completely
Hm, if that doesn't work, I am not sure. You could try overwriting the update logic when reordered
I mean the display for both table, and reordeable action table works. The problem comes when I reorder items and save to the database.
$orderColumn becomes "products.order_to_display" and I guess eloquent just does not like dot notation here.
Yeah, I understand. That's why I said: Maybe you need to overwrite that
reorderTable()
logicOh I can do this from the ListRecords :}
Thanks I will try. 🙂
@Dennis Koch do you know when this part gets triggered? I could not find anything in the documentation yet. I wonder if we could just trim prefixes with dot and take any string after dot.
Seems like that's used for columns on a relation.
Yeh, just was wondering if dot notation plays in here. I do not see this in a code, so maybe not.
Does reordering column make column 's value swap or make changes that whole column values
all the values change
Does filament have something like we can swap two values in list record not whole column values
i dont think so