Reputation: 1196
So this is my json output
{"draw": 1, "recordsTotal": 2, "recordsFiltered": 2, "data": [["2014-08-01","34","84"],["2014-08-02","36","61"]]}
and using DataTable I can build my tables
<table>
<tr>
<td>2014-08-01</td>
<td>34</td>
<td>84</td>
</tr>
<tr>
<td>2014-08-02</td>
<td>36</td>
<td>61</td>
</tr>
</table>
well thats my table you get the picture... so the first column is a date, and second is an ID and the 3rd is just a value... I'd like to add a link to the ID
<table>
<tr>
<td>2014-08-01</td>
<td><a href="foo.php?id=34">34</a></td>
<td>84</td>
</tr>
<tr>
<td>2014-08-02</td>
<td><a href="foo.php?id=36">36</a></td>
<td>61</td>
</tr>
</table>
and this is the code I use for the "ajax"
$('#tr1').dataTable({
"processing": true,
"bServerSide": false,
"sAjaxSource": "rep/cm.php?pm",
"sServerMethod": "GET",
"wPaginationType": "full_numbers"
});
So, how do I add that link?
Upvotes: 0
Views: 2060
Reputation: 2328
I think you could use aoColumnDefs
together with mData
and mRender
look at DataTAbles.
mData
and mRender
allows to manipulate data for display without altering the underlying data for the table.
$('#tr1').dataTable({
"processing": true,
"bServerSide": false,
"sAjaxSource": "rep/cm.php?pm",
"sServerMethod": "GET",
"wPaginationType": "full_numbers",
"aoColumnDefs": [
{ "aTargets": [1], "mData":1,
"mRender": function ( data, type, full ) {
return '<a href="foo.php?id='+ data +'">'+ data + '</a>';
}},
]
});
Upvotes: 0
Reputation: 998
Modify your file "rep/cm.php?pm" to return a different json array which already contains the links instead of the page id numbers.
This should be your json output:
{"draw": 1, "recordsTotal": 2, "recordsFiltered": 2, "data": [["2014-08-01","<a href=\"foo.php?id=34\">34</a>","84"],["2014-08-02","<a href=\"foo.php?id=36\">36</a>","61"]]}
Upvotes: 0