The pager on a form doesn't update upon first submit of the form 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-&gt;condition('type', 'my_node_type')
            -&gt;condition('status', 1);

        $pager_params = [];
        if ($event_types != []){
            $q-&gt;condition('field_art_der_veranstaltung', $event_types, 'IN');
        }

        $events = $q-&gt;sort('created', 'DESC')-&gt;pager(10)-&gt;execute();

        $nodes = Node::loadMultiple($events);

        $rows = [];

        foreach($nodes as $node){
            $rows[$node-&gt;id()] = [
                'nid' =&gt; $node-&gt;id(),
                'title' =&gt; $node-&gt;getTitle(),
            ];
        };

        $form['nodes_container']['nodes'] = [
            '#type' =&gt; 'tableselect',
            '#title' =&gt; $this-&gt;t('Events'),
            '#options' =&gt; $rows,
            '#header' =&gt; $header,
            '#empty' =&gt; $this-&gt;t('No events found'),
        ];

        $form['nodes_container']['pager'] = [
            '#type' =&gt; 'pager',
        ];
Seemingly, I have fould the solution.
Namely, to avoid it, I set the Element property for the pager explicitely.

Here are fragments of code.

$nodes = $q-&gt;sort('created', 'DESC')-&gt;pager(10, 0)-&gt;execute();

/// code here

$form['nodes_container']['pager'] = [
  '#type' =&gt; 'pager',
  '#element' =&gt; 0,
  '#parameters' =&gt; $pager_params,
];


Unfortunately, I didn't have a time to debug and find out why it didn't worked before but it works now. Newertheless, it works.