Using DataTables to output column with a link
Using DataTables to output column with a link
Hi, I'm using DataTables to list products on sale on my website (I have about 1000 products to list). I am using it with server-side processing and it works with no problems after I enter the details of my table in my script. Here is my site: http://neoshop.xtreemhost.com/shop/search.php
Now I'm wondering if there is any way to have one column be formatted in a way like this:
The Name of the Product
where:
<?php
$url = index.php?p=ProductId;
?>
and ProductId is the column on the very left.
Any help please? Thanks in advance.
Now I'm wondering if there is any way to have one column be formatted in a way like this:
The Name of the Product
where:
<?php
$url = index.php?p=ProductId;
?>
and ProductId is the column on the very left.
Any help please? Thanks in advance.
This discussion has been closed.
Replies
in fnRowCallback, you can grab the id via aData[0], and you can "rewrite" nRow so that there is an anchor link in the Product name column. Concatenate the id into the right place in a new string, and you're done.
I can probably come up with some sample code for you if that's not enough to go by. Be sure to check out the fnRowCallback documentation to see how it could be done, though-- if you read up on that function, you'll beat me to it. ;-)
[code]$(document).ready(function() {
$('#example').dataTable( {
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
{
$('td:eq(1)', nRow).html( 'aData(1)' );
}
}
} );
} );[/code]
How do I concatenate aData properly?
As far as I can see, this should work (but I admit I haven't tested it):
[code]
$(document).ready(function() {
$('#example').dataTable( {
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
$('td:eq(1)', nRow).html( ''+aData[1]+'' );
return nRow;
}
} );
} );
[/code]
A node was not returned by fnRowCallback
return nRow;
below the code that modifies the row.
Thanks a lot for your help!