I have a table of users. and I need to be able to filter them by 'Group'. So when user selects option from drop-down list, I want not the whole page but only users table to reload and display users from that group
This is twig for users table
Filter by group
<select class="filter-users">
<option selected></option>
{% for group in groups %}
<option>{{ group.name }}</option>
{% endfor %}
</select>
<table id="dataTable">
<tbody>
{% for user in users %}
<tr>
<td>{{user.id}}</td>
<td>{{user.fullName}}</td>
</tr>
{% endfor %}
</tbody>
</table>
This action to get users by group name
/**
* @Route("/filter", name="users_filter")
*/
public function filterAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$group = $request->request->get('group');
$users = $em->getRepository('AppBundle:User')->findBy(['group' => group]);
return $this->render('AppBundle:User:list.html.twig', [
'users' => $users
]);
}