Dcat Admin 应用自定义排序规则 作者: Shine 时间: 2025-07-04 分类: PHP 评论 > 为了后续方便查找,故作记录 ❌ 起初我一直以为是这样配置,如果是这样配置,其实是会被 ` parent::get($model);` 里面的方法重置掉排序 ```php where('type', 0); $this->addOrderBy($model, 'is_active', 'desc', 'int'); $this->addOrderBy($model, 'order', 'asc', 'int'); return parent::get($model); } } ``` ✅ 其实正确的应该是这样配置 ```php where('type', 0); $this->setSort($model); $this->setPaginate($model); // 写到这里 $query = $this->newQuery() ->orderByDesc('is_active') ->orderBy('order'); if ($this->relations) { $query->with($this->relations); } return $model->apply($query, true, $this->getGridColumns()); } } ```