Answer the question
In order to leave comments, you need to log in
How to set your own ActiveDataProvider parameters?
Good afternoon. The question of such a plan, I display the table, but I do not need the output of the table for everything, I need to weed out the first record.
If you change the offset value in the yii\data\ActiveDataProvider method in the prepareModels method, then everything works, but it’s not ice to change the yii class itself, I created my own inherited, I change the offset, but nothing happens. How can I set the offset?
The method itself
protected function prepareModels()
{
if (!$this->query instanceof QueryInterface) {
throw new InvalidConfigException('The "query" property must be an instance of a class that implements the QueryInterface e.g. yii\db\Query or its subclasses.');
}
$query = clone $this->query;
if (($pagination = $this->getPagination()) !== false) {
$pagination->totalCount = $this->getTotalCount();
$query->limit($pagination->getLimit())->offset($pagination->getOffset());
}
if (($sort = $this->getSort()) !== false) {
$query->addOrderBy($sort->getOrders());
}
return $query->all($this->db);
}
Answer the question
In order to leave comments, you need to log in
Instead of it is not simpler to exclude the first record by means of request?
You pass a list of models to the provider (Model::find()), so what prevents you from removing your first entry in the filters of the search itself from the list of models before passing it to the output?
maybe there is an option to set the offset somehow in the view where the table is displayed
$models = Mymodel::find()->all();
unset($models[0]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question