In the Sonata Admin Bundle you have a list view where you can add fields you want to show in your table.
At the bottom of the table you have the number of results and pagination. I like the pagination and items per page. But I would like to show ALL the items at the load of the page. So all the items are shown on the page but you can still choose to decrease the number of results per page.
The problem is I don't have a clue on how to do this. Can someone set me on my way?
In SonataAdmin 3.x to have all rows by default you need to do the following :
1 - Add _per_page = All to $datagridValues
:
protected $datagridValues = array(
'_sort_order' => 'ASC',
...
'_per_page' => 'All',
);
2 - Add All to $perPageOptions:
protected $perPageOptions = [16, 32, 64, 128, 192, 'All'];
3 - Set $maxPerPage to All:
protected $maxPerPage = 'All';
Actually, it is possible to do.
You have in you EntityAdmin
to
a) Define a list of possible "Results per page" values.
Now it is
protected $perPageOptions = array(16, 32, 64, 128, 192);
So the easiest solution could be just to put a new really big number, foe example
protected $perPageOptions = array(16, 32, 64, 128, 192, 1000000);
But if you want to make really "all", then you must do
protected $perPageOptions = array(16, 32, 64, 128, 192, 'All');
and then
2) redefine a method EntityAdmin::buildDatagrid()
to process this 'All'
value of $filterParameters['_per_page']
class YourAdmin extends AbstractAdmin
{
protected $perPageOptions = [64, 128, 256, 'All'];
protected $datagridValues = [
'_per_page' => 'All',
];
protected $maxPerPage = 'All';
...
}
If you find $maxPerPage variable as strange or redundant ask him @author Thomas Rabaix thomas.rabaix at sonata-project dot org