I've trying to add a link to Edit and Delete column to perform desirable actions. I need help in implementing it. I've tried several suggested methods on the internet, but none did the job for me. Maybe I am doing something wrong.
Here is my Controller.php
public function getAdList(){
$limit = 3;
$query = \Drupal::database();
$result = $query->select('ad_form_submissions','u')
->fields('u',['id','name','crop_category','crop_type','quantity','price'])
->extend('Drupal\Core\Database\Query\PagerSelectExtender')->limit($limit)
->execute()->fetchAll(\PDO::FETCH_OBJ);
$data = [];
$count = 1;
$params = \Drupal::request()->query->all();
if(empty($params) || $params['page'] == 0){
$count=1;
}else if($params['page'] == 1){
$count = $params['page'] + $limit;
}else{
$count = $params['page'] * limit;
$count++;
}
foreach($result as $row){
$data[] = [
'S_no'=> $count.".",
'ID'=> $row->id,
'Name'=> $row->name,
'Crop Category'=> $row->crop_category,
'Crop Type'=> $row->crop_type,
'Quantity'=> $row->quantity,
'Price'=> $row->price,
'Edit' => 'Edit',
'Delete'=>'Delete'
];
$count++;
}
$header = array('S_no','ID','Name','Crop Category','Crop Type','Quantity','Price','Edit','Delete');
$build['table'] = [
'#type'=>'table',
'#header'=>$header,
'#rows'=>$data,
'#empty' => t('No users found'),
];
$build['parger'] = [
'#type'=>'pager'
];
return [
$build,
'#title'=> 'Submit Ad List'
];
}
Clarification: I want to perform the Edit and Delete Task on the selected row.