KnpLabs/KnpPaginatorBundle — Issue #89: Adding ->setSortedBy($key, $direction) to $paginator
Author: loostro
Created: 2012-02-27 10:35:12+00:00
State: open

I need to replace tags with tags in sortable_link.html.twig.

I'll try to shortly explain why:

I want creation of usergroup to be in one template/action. I use jQuery and $.ajax ($.post) to do that - but I want the same functionality for javascript-disabled users.

I have an action /usergroup/create with a form containing fields such as: name, description and roles (which is a collection of Role Names).
Below this form, I have a Paginated by KNP Paginator list of roles.

I created a add/remove role functionality and everything works great - except sorting.

If I click an anchor -> then I go to the href URL, but my form input is not submitted. I don't want users to re-enter their data into form every time they sort the roles list.

So I replaced tags with

This way my form is submitted and in the controller I can get the {{ key }} value by $key = $request->request->get('sort')

What I do with this value next is:

$request->query->set('sort', $key); //setting request GET variable as if the url was someurl?sort=key)
$request->query->set('direction', 'asc') // or 'desc' depending on wheather the array is already sorted by $key

The problem is that KNP Paginator does not care - becouse the sorting takes place before I set my GET variables.

I am still learning and I don't understand Events and Subscribers in KNP components - please help me - how should/could I (in my controller) force KNP paginator to sort by $key = $request->request->get('sort')

Or maybe you could add some function to $paginator (like setTemplate) -- setSortedBy( $key , $direction) ??