我正在drupal 7中编写一个模块,我想在内容管理中制作一个类似表格的表格。我可以制作这样的排序表,但是如何在标题和每一行中添加复选框?
这是我的代码:
$header = array(
array('data' => 'Title', 'field' => 'title'),
array('data' => 'Created', 'field' => 'created','sort' => 'desc'),
array('data' => 'Published', 'field' => 'status'),
array('data' => 'Action'),
);
$result = db_select('news','n')->extend('PagerDefault')
->fields('n')
->limit(10) //This is we can change the number of rows
->extend('TableSort') // Sorting Extender
->orderByHeader($header)// Field to sort on is picked from $header
->execute()->fetchAll();
$path = drupal_get_path("module","tuan_nguyen");
foreach($result as $row){
$img = $path."/del.png";
if($row->status == 1){
$img = $path."/check.png";
}
$date = format_date($row->created,'medium','','Asia/Ho_Chi_Minh');
$rows[$row->id] = array(
l($row->title,'admin/tuan_nguyen/news/edit/'.$row->id),
$date,
"<img width='30px' height='30px' src='".$img."'/>",
l('Edit','admin/tuan_nguyen/news/edit/'.$row->id).' / '.l('Del','admin/tuan_nguyen/news/del/'.$row->id),
);
}
//Create a render array ($build) which will be themed as a table with a pager
$build['tuan_table'] = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' =>t('Table is empty'),
);
//attach the pager theme
$build['tuan_pager'] = array('#theme' => 'pager');
return $build;