Get all data from dataProvider

Hi, was looking the docs and other places but couldn’t find an answer to this.

I wanna extract all the data (or rather, get all the models) from a dataprovider. Something like:




$dataProvider = new ActiveDataProvider([

    'query' => $query,

]);


$dataProvider->getModels()



The problem with this, is that it only returns the models from the current page. I need to get all the models from the dataProvider. I think this can be done by setting the pagination property to false, like:




$dataProvider = new ActiveDataProvider([

    'query' => $query,

    'pagination' => false

]);


$dataProvider->getModels();



But i don’t know if this is the correct way to do it. How should i approach this? thanks in advance.




$dataProvider->query->all();



1 Like

Tried to use what you mentioned but it’s giving me php fatal error (maximun execution time exceeded). I think this has more to do with my query than anything else, or maybe the $dataProvider has to many records.

This is the query that populates my $dataProvider:




$query = Persona::find()->joinWith('interes')->joinWith('reconocimiento')->joinWith(['empresas', 'empresas.historicoSocio'])->groupBy(['per_id']);



This returns more than 30.000 records (37.129 to be precise).

Is there a way i can get all the data/models from this query? or just all the keys in in the $dataProvider currently (all pages).

Any help is appreciated, thanks.

If you need 30,000 IDs in your code, maybe you should re-think your approach.

If you absolutely need them, try a plain query:

http://www.yiiframework.com/doc-2.0/guide-db-query-builder.html

I don’t really need to get the 30.000 IDs, but i would like to get the IDs in the grid after the user perfoms a search. Let’s say, grid returns 100 records after applying some filters, the grid shows 20 per page and i need to get all 100 IDs to perfom an action. Is a plain query the only way to do this? or this there any other way around it?

I thought about using a checkbox column to select all rows and get the IDs of the selected rows (using yii\grid\CheckboxColulmn) but i don’t know how to select all rows at once.

Thanks for your answer, will look further on that option.

How about using




$dataProvider->query->all();



only after the user performed a search? Or check "getTotalCount()" first, something like that.

I’m testing that right now. Problem with that is it limits the amount of records the user can perform the desired action with. Specifically, i want to send all the keys of the rows in the grid when the user clicks on a button so i can populate another table with those keys.

Will keep looking for other ways to do it, thanks for your help.

On a second thought checkbox column seems like a good solution, is there any way to select all rows across all pages in the gridview? I can select all checkbox in the current page via jQuery but don’t know how to select all checkbox in all pages at once. Was looking at this SO post but this uses jquery data tables, so i don’t know the proper way to implement it without it.

P.S: wasn’t sure if i should open a new issue for this so i ended up re-posting here. Sorry if it wasn’t correct.