Created
August 23, 2019 03:40
-
-
Save haifahrul/2277d119eeb0b1d0274b2891d488a9cd to your computer and use it in GitHub Desktop.
Yii2 Grid Jeasyui - Controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function actionGetData() | |
{ | |
$request = Yii::$app->request; | |
Yii::$app->getResponse()->format = 'json'; | |
$query = (new \yii\db\Query()) | |
->select('m_unit.*, m_people.*') | |
->from("m_people") | |
->leftJoin('m_unit', 'm_unit.id = unit_id'); | |
// searching | |
if (($q = $request->post('q'))) { | |
} | |
if (($request->post('searchtype') == 'str')) { | |
$query->andFilterWhere(['like', 'LOWER(' . $request->post('searchdata') . ')', strtolower($request->post('searchvalue'))]); | |
} else if (($request->post('searchtype') == 'int')) { | |
$query->andFilterWhere([$request->post('searchdata') => $request->post('searchvalue')]); | |
} | |
// sorting | |
if (($sort = $request->post('sort'))) { | |
$order = $request->post('order', 'asc'); | |
$query->orderBy([$sort => $order == 'asc' ? SORT_ASC : SORT_DESC]); | |
} else { | |
} | |
// paging | |
$limit = $request->post('rows', 15); | |
$page = $request->post('page', 1); | |
$total = $query->count(); | |
$query->offset(($page - 1) * $limit)->limit($limit); | |
return [ | |
'total' => $total, | |
'rows' => $query->all(), | |
]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment