当用户第一次访问页面时,ListEntries表将按id进行升序,并且表头中的排序图标没有一个是活动的。
我希望将ListEntries表按我选择的列排序,包括使此列旁边的图标处于活动状态(升或降)。
当用户访问页面时,是否有一种方法可以让ListEntries表按我选择的列排序?
发布于 2020-09-10 14:27:36
这可以通过操作request对象来实现,在某些圆圈中可能会对请求对象皱眉。
此解决方案还将更新相应列上的order图标。
有许多方法可以实现这一点,但一种方法是将以下内容添加到Controller的setupListOperation()方法中。
/** @var \Illuminate\Http\Request $request */
$request = $this->crud->getRequest();
if (!$request->has('order')) {
$request->merge(['order' => [
[
'column' => 'column-index-here',
'dir' => 'asc'
]
]]);
}发布于 2019-07-31 14:23:18
在Controller的setup()方法中,可以使用:
$this->crud->orderBy('name', 'DESC');传递给orderBy()语句的任何内容都将用于雄辩的查询。
默认情况下,实际属性的列(在数据库中有一个对应列)应该是orderable。但是您也可以手动为列指定'orderable' => true或定义您自己的订单逻辑。请注意,默认情况下,关系列(1-n,NOT )、model_function或model_function列是不可排序的,但是可以使用orderLogic对它们进行排序。
希望能帮上忙。
发布于 2021-03-18 12:55:26
使用这个键orderable它是一个布尔值
this->crud->addColumn([
'label' => 'Category',
'type' => 'select',
'name' => 'category_id', // the db column for the foreign key
'entity' => 'category', // the method that defines the relationship in your Model
'attribute' => 'name', // foreign key attribute that is shown to user
'orderable' => true,
'orderLogic' => function ($query, $column, $columnDirection) {
return $query->leftJoin('categories', 'categories.id', '=', 'articles.select')
->orderBy('categories.name', $columnDirection)->select('articles.*');
}
]);https://stackoverflow.com/questions/57253900
复制相似问题