【发布时间】:2017-03-29 11:18:58
【问题描述】:
我正在使用 DataTables 来生成表格。有一列包含用户名
例如:...
当有人单击用户名时,我需要此列中的每一行都有一个超链接,然后它会重定向到编辑页面,例如,第一行将是查看的超链接?id=1321755 等。
我能做到的最简单的方法是什么?
这是我的观点代码:
<table id="book-table" class="table table-bordered table-striped table-hover">
<thead>
<tr class="">
<th>Name</th>
<th>Date</th>
<th>Work</th>
<th>Partner</th>
<th>Director</th>
<th>Time</th>
<th>Task</th>
<th>Status</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<script type="text/javascript">
$(document).ready(function() {
$('#book-table').DataTable({
"ajax": {
url : "<?php echo site_url("digital_admin/hodm/books_page") ?>",
type : 'GET'
},
});
});
</script>
这是我的控制器代码:
public function books_page()
{
// Datatables Variables
$draw = intval($this->input->get("draw"));
$start = intval($this->input->get("start"));
$length = intval($this->input->get("length"));
$books = $this->pojo->get_books();
$data = array();
foreach($books->result() as $r) {
$data[] = array(
$r->user_name,
$r->date,
$r->t_name,
$r->partner,
$r->director,
$r->duration,
$r->task,
$r->status
);
}
$output = array(
"draw" => $draw,
"recordsTotal" => $books->num_rows(),
"recordsFiltered" => $books->num_rows(),
"data" => $data
);
echo json_encode($output);
exit();
}
请帮我找出答案
【问题讨论】:
-
@markpsmith 您提到的链接仅适用于一行,而我的问题是从数据库中获取的大量行
-
最简单的方法是将链接放在查询中,例如:
'<a href="view?id='. $r->user_id .'" >'. $r->user_name .'</a>'; -
@MichaelK 我没听懂你。我如何添加链接和位置
标签: jquery codeigniter datatables