title: How to reuse sonata Admin paginator with a custom crud controller
body: <p>I have a custom CRUD controller with an action which retrieves a custom doctrine result set and passes it to a custom template. Is it possible to make use of Sonata Admin's pagination mechanism  without reusing the standard list templates?</p>
  
  <p>If so, what object format does the paginator expect? I could not see any mention of this in the <a href="http://sonata-project.org/bundles/admin/master/doc/cookbook/recipe_custom_action.html" rel="nofollow">documentation</a></p>
  
  <p>The template I would need to populate with results would be base_results.html.twig:</p>
  
  <pre><code>{% block num_pages %}
      {{ admin.datagrid.pager.page }} / {{ admin.datagrid.pager.lastpage }}
      &amp;nbsp;-&amp;nbsp;
  {% endblock %}
  
  {% block num_results %}
      {% transchoice admin.datagrid.pager.nbresults with {'%count%': admin.datagrid.pager.nbresults} from 'SonataAdminBundle' %}list_results_count{% endtranschoice %}
      &amp;nbsp;-&amp;nbsp;
  {% endblock %}
  {% block max_per_page %}
      &lt;label class="control-label" for="{{ admin.uniqid }}_per_page"&gt;{% trans from 'SonataAdminBundle' %}label_per_page{% endtrans %}&lt;/label&gt;
      &lt;select class="form-control per-page small" id="{{ admin.uniqid }}_per_page"&gt;
          {% for per_page in admin.getperpageoptions %}
              &lt;option {% if per_page == admin.datagrid.pager.maxperpage %}selected="selected"{% endif %} value="{{ admin.generateUrl('list', {'filter': admin.datagrid.values | merge({'_page': 1, '_per_page': per_page})}) }}"&gt;
                  {{ per_page }}
              &lt;/option&gt;
          {% endfor %}
      &lt;/select&gt;
  {% endblock %}
  </code></pre>
  
  <p>If I want to add an additional constraint on the result set, how would I adapt the following code from Sonata's list action?</p>
  
  <pre><code>if (false === $this-&gt;admin-&gt;isGranted('LIST')) {
              throw new AccessDeniedException();
          }
  
          $datagrid = $this-&gt;admin-&gt;getDatagrid();
          $formView = $datagrid-&gt;getForm()-&gt;createView();
  
          // set the theme for the current Admin Form
          $this-&gt;get('twig')-&gt;getExtension('form')-&gt;renderer-&gt;setTheme($formView, $this-&gt;admin-&gt;getFilterTheme());
  
          return $this-&gt;render($this-&gt;admin-&gt;getTemplate('list'), array(
              'action'     =&gt; 'list',
              'form'       =&gt; $formView,
              'datagrid'   =&gt; $datagrid,
              'csrf_token' =&gt; $this-&gt;getCsrfToken('sonata.batch'),
          ));
  </code></pre>