public function actionList()
{
$where['storeid'] = $this->storeid;
$where['status'] = [Table::STATUS_NORMAL, Table::STATUS_PEND];
$model = new ActiveDataProvider([
'query' => Table::find()->where($where)->with(
[
'tableType'=>function($query){
$query->andWhere(['status'=>Table::STATUS_NORMAL,'storeid'=>$this->storeid]);
},
'area'=>function($query){
$query->andWhere(['status'=>Table::STATUS_NORMAL,'storeid'=>$this->storeid]);
},
]
),
'pagination' => [
'pageSize' => 10,
],
]);
//添加以下代码,自定义排序
$model->setSort([
'attributes' => [
'area.areaname' => [
'asc' => ['areaid' => SORT_ASC],
'desc' => ['areaid' => SORT_DESC],
'label' => '餐桌楼层'
],
'tablenum'=>[
'asc'=>['tablenum'=>SORT_ASC],
'desc' => ['tablenum' => SORT_DESC],
'label' => '餐桌排序'
]
]
]);
return $this->render('list', [
'model' => $model,
]);
}
yii2使用hasOne联查的数据,同样实现在列表中的排序功能
最新推荐文章于 2022-11-18 15:57:33 发布