Commit 50ea97bd by Carsten Brandt

edited sorting guide

fixes #6682
parent ecadfa43
Sorting
=======
Sometimes data to be displayed should be sorted according to one or several attributes. If you are using
[data provider](output-data-providers.md) with one of the [data widgets](output-data-widgets.md) it is
handled for you automatically. If not, you should create [[\yii\data\Sort]] instance in controller, configure it and
apply it to the query and then pass it to the view where it can be used to create links to sort by attributes.
Sometimes the data that is to be displayed should be sorted according to one or several attributes. If you are using
a [data provider](output-data-providers.md) with one of the [data widgets](output-data-widgets.md), sorting is
handled for you automatically. If not, you should create a [[yii\data\Sort]] instance, configure it and
apply it to the query. I can also be passed to the view, where it can be used to create links to sort by certain attributes.
A typical usage example is as follows,
......@@ -49,4 +49,8 @@ foreach ($models as $model) {
In the above, we declare two attributes that support sorting: `name` and `age`.
We pass the sort information to the Article query so that the query results are
sorted by the orders specified by the Sort object. In the view, we show two hyperlinks
that can lead to pages with the data sorted by the corresponding attributes.
\ No newline at end of file
that can lead to pages with the data sorted by the corresponding attributes.
The [[yii\data\Sort|Sort]] class will optain the parameters passed with the request automatically
and adjust the sort options accordingly.
You can adjust the parameters by configuring the [[yii\data\Sort::$params|$params]] property.
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment