Reputation: 11265
I'm passing data to datatable
$records["data"][] = array(
'<input type="checkbox" name="id[]" value="'.$id.'">',
$id,
'12/09/2013',
'Jhon Doe',
'Jhon Doe',
'450.60$',
rand(1, 10),
'<span class="label label-sm label-'.(key($status)).'">'.(current($status)).'</span>',
'<a href="javascript:;" class="btn btn-xs default"><i class="fa fa-search"></i> View</a>',
);
I want add to every table row link, it mean that you can click on datatable row and will be directed to some url, every row
url will be different (that url I must set). My question is how to set that row
ulr ?
Upvotes: 0
Views: 2216
Reputation: 997
You can use fnRowCallback event of datatable and bind click event to each row.
var oTable = $('#data').dataTable({
"fnRowCallback": function (nRow, aData, iDisplayIndex) {
// Bind click event
$(nRow).click(function() {
window.open('http://example.com');
//OR
window.open(aData.url);
});
return nRow;
}
});
Upvotes: 3
Reputation: 6820
Link to your detail page (I called it dataitem.php
for example), and pass the id in the query string:
'<a href="dataitem.php?id='.$id.'" class="btn btn-xs default">View</a>'
Then, in dataitem.php
, read the id from the query string so you know which row to display.
Upvotes: 0