tableSort example

if ($search) {
      $query->condition('alias', $search, 'CONTAINS');
    }

    // Only add the pager if a limit is specified.     if ($this->limit) {
      $query->pager($this->limit);
    }

    // Allow the entity query to sort using the table header.     $header = $this->buildHeader();
    $query->tableSort($header);

    return $query->execute();
  }

  /** * {@inheritdoc} */
  public function render() {
    $keys = $this->currentRequest->query->get('search');
    $build['path_admin_filter_form'] = $this->formBuilder->getForm(PathFilterForm::class$keys);
    $build += parent::render();

    

  public function testTableSort() {
    $header = [
      ['data' => 'ID', 'specifier' => 'id'],
      ['data' => 'Number', 'specifier' => 'number'],
    ];

    // Sort key: id     // Sorting with 'DESC' upper case     $this->queryResults = $this->entityStorage->getQuery()
      ->tableSort($header)
      ->sort('id', 'DESC')
      ->execute();
    $this->assertSame(['7', '6', '5', '4', '3', '2', '1']array_values($this->queryResults));

    // Sorting with 'ASC' upper case     $this->queryResults = $this->entityStorage->getQuery()
      ->tableSort($header)
      ->sort('id', 'ASC')
      ->execute();
    $this->assertSame(['1', '2', '3', '4', '5', '6', '7']array_values($this->queryResults));

    

    \Drupal::getContainer()->get('request_stack')->push($request);

    $header = [
      'id' => ['data' => 'Id', 'specifier' => 'id'],
      'type' => ['data' => 'Type', 'specifier' => 'type'],
    ];

    $this->queryResults = array_values($this->storage
      ->getQuery()
      ->accessCheck(FALSE)
      ->tableSort($header)
      ->execute());
    $this->assertBundleOrder('asc');

    $request->query->add([
      'sort' => 'desc',
    ]);
    \Drupal::getContainer()->get('request_stack')->push($request);

    $header = [
      'id' => ['data' => 'Id', 'specifier' => 'id'],
      'type' => ['data' => 'Type', 'specifier' => 'type'],
    ];
'changed' => [
        'data' => $this->t('Updated'),
        'specifier' => 'changed',
        'sort' => 'desc',
        'class' => [RESPONSIVE_PRIORITY_LOW],
      ],
      'operations' => $this->t('Operations'),
    ];
    $cids = $this->commentStorage->getQuery()
      ->accessCheck(TRUE)
      ->condition('status', $status)
      ->tableSort($header)
      ->pager(50)
      ->execute();

    /** @var \Drupal\comment\CommentInterface[] $comments */
    $comments = $this->commentStorage->loadMultiple($cids);

    // Build a table listing the appropriate comments.     $options = [];
    $destination = $this->getDestinationArray();

    $commented_entity_ids = [];
    


  /** * {@inheritdoc} */
  public function load() {
    $entity_query = $this->storage->getQuery();
    $entity_query->accessCheck(TRUE);
    $entity_query->condition('uid', 0, '<>');
    $entity_query->pager(50);
    $header = $this->buildHeader();
    $entity_query->tableSort($header);
    $uids = $entity_query->execute();
    return $this->storage->loadMultiple($uids);
  }

  /** * {@inheritdoc} */
  public function buildHeader() {
    $header = [
      'username' => [
        'data' => $this->t('Username'),
        
Home | Imprint | This part of the site doesn't use cookies.