Trait rootlocal\widgets\sortable\SortableGridQueryTrait
Trait SortableGridQueryTrait
Trait for Sortable Grid Query class Model
Example:
- Query class:
class BookQuery extends ActiveQuery
{
use SortableGridQueryTrait;
// ...
}
- Model class:
class Book extends ActiveRecord
{
// ...
public static function find(): BookQuery
{
return new BookQuery(get_called_class());
}
// ...
}
- Sorting:
$query = Book::find()->sortByOrder();
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
$modelClass | \yii\db\ActiveRecord | rootlocal\widgets\sortable\SortableGridQueryTrait |
Public Methods
Method | Description | Defined By |
---|---|---|
sortByOrder() | Order Sorting by 'sortableAttribute' rootlocal\widgets\sortable\SortableGridBehaviorInterface::getSortableAttribute() | rootlocal\widgets\sortable\SortableGridQueryTrait |
Property Details
Method Details
Order Sorting by 'sortableAttribute' rootlocal\widgets\sortable\SortableGridBehaviorInterface::getSortableAttribute()
public \yii\db\ActiveQuery sortByOrder ( ) |
public function sortByOrder(): ActiveQuery
{
$modelClass = $this->modelClass;
/* @var $model SortableGridBehaviorInterface|ActiveRecordInterface */
$model = $modelClass::instance();
return $this->orderBy([$model::tableName() . '.' . $model->getSortableAttribute() => SORT_ASC]);
}