Skip to content

Instantly share code, notes, and snippets.

@opotemkin
Created March 2, 2017 17:40
Show Gist options
  • Save opotemkin/3e37122f8e275efa011330d238415b96 to your computer and use it in GitHub Desktop.
Save opotemkin/3e37122f8e275efa011330d238415b96 to your computer and use it in GitHub Desktop.
Yii2 new ArrayDataProvider + setSort
// first
$dataProvider = new ArrayDataProvider(['query' => $query]);
$dataProvider->setSort([
'attributes' => [
'time',
'total',
'average-price',
],
'defaultOrder' => ['time' => SORT_ASC]
]);
// second
$dataProvider = new ArrayDataProvider([
'allModels' => $models,
'pagination' => false,
'sort' => [
'attributes' => ['category', 'seq', 'duration', 'info'],
'defaultOrder' => [
'seq' => SORT_ASC,
],
],
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment