-3

I'm currently studying Drupal 8, and I already learned simple CRUD in Drupal 8. Now I want to learn how to add filters or search on Drupal tables programmatically. How can I do that? The code below is just showing the table content.

foreach($results as $data){
  $delete = Url::fromUserInput('/mydata/form/delete/'.$data->id);
  $edit   = Url::fromUserInput('/mydata/form/mydata?num='.$data->id);

  //print the data from table
  $rows[] = array(
    'name' => $data->name,
    'mobilenumber' => $data->mobilenumber,
    //'email' => $data->email,
    'age' => $data->age,
    'gender' => $data->gender,
    //'website' => $data->website,
    \Drupal::l('Delete', $delete),
    \Drupal::l('Edit', $edit),
  );
}

//display data in site

$form['table'] = [
  '#type' => 'table',
  '#header' => $header_table,
  '#rows' => $rows,
  '#empty' => t('No users found'),
];
  • Drupal Answers doesn't provide personalized tutorial requests, nor does it provide code reviews. Maybe ask those kind of questions in a forum. One advice: Always look into how other modules or core solved the same problem first. – leymannx Aug 12 at 7:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.