I have a form with filter checkboxes, submit button, results in tableselect and pager.
When I set some checkboxes and press the submit button, a query should be reexecuted, data should be placed into the tableselect and pager should be updated, because new data size can be different with old one.
When I do it the first time, query is executed successfully, tableselect also is updated without problems. But the pager doesn't want to be updated. And to update the pager I have to press the submit button second time. But it occurs only I pressed the submit button after the page with the form has been loaded.
Could you clarify me, how can I update the pager after first submission of the form ?
Here is a fragment of my code with the tableselect and the pager.
$q = \Drupal::entityQuery('node');
$q = $q->condition('type', 'my_node_type')
->condition('status', 1);
$pager_params = [];
if ($event_types != []){
$q->condition('field_art_der_veranstaltung', $event_types, 'IN');
}
$events = $q->sort('created', 'DESC')->pager(10)->execute();
$nodes = Node::loadMultiple($events);
$rows = [];
foreach($nodes as $node){
$rows[$node->id()] = [
'nid' => $node->id(),
'title' => $node->getTitle(),
];
};
$form['nodes_container']['nodes'] = [
'#type' => 'tableselect',
'#title' => $this->t('Events'),
'#options' => $rows,
'#header' => $header,
'#empty' => $this->t('No events found'),
];
$form['nodes_container']['pager'] = [
'#type' => 'pager',
];