add a hyperlink to a table element

add a hyperlink to a table element

mikeddd123mikeddd123 Posts: 6Questions: 0Answers: 0
edited April 2011 in General
Firstly thank you allan for this amazing plugin!
I've got this code which seems to be working but I'm not sure if its correct.
I'm trying to add a hyperlink into a cell.

Thanks in Advance!!!

aData[5] - contains the link
aData[3] - contains the text

Here is the sample code:
[code]
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
/* Append the head to the default row class name */
if ( aData[3] == "Click Me" )
{ /*.....Is this part below correct?.....*/
$('td:eq(2)', nRow).html( 'Click Me' );
}
return nRow;
},
} );
} );
[/code]

Replies

  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    I would suggest using fnRender ( http://datatables.net/usage/columns#fnRender ) rather than fnRowCallback. The row callback is called every time the row is shown in the table - which probably isn't what you want here. It looks like the code above might work (does it - minus the trailing comma which will break IE...?) - but I think fnRender is probably more suitable for this case.

    Allan
  • mikeddd123mikeddd123 Posts: 6Questions: 0Answers: 0
    edited May 2011
    Is there anything wrong with this code below?

    As you can see below I'm currently using a local server (wamp).

    I'm getting this error when I load the table "DataTables warning: JSON data from server could not be parsed. This is caused by a JSON formatting error.", and when I refresh the table loads normal.

    I'm also getting this error in the processing.php file "Notice: Undefined index: sEcho in......" how can I resolve this?

    Thanks!

    [code]

    $(document).ready(function() {
    $('#example').dataTable( {
    "bProcessing": true,
    "bServerSide": true,
    "bJQueryUI": true,
    "sPaginationType": "full_numbers",
    "aoColumns": [
    /*id*/ { "bVisible": false},
    /*name*/ null,
    /*phone#*/ null,
    /*click me*/ { "bSortable": false, "fnRender": function ( oObj ) {
    return ''+ oObj.aData[3] +'';}, "aTargets": [ 0 ]},
    /*date*/ null,
    /*hurl*/ { "bVisible": false},
    ],
    "aLengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
    "sAjaxSource": "http://localhost/table/processing.php",
    "aaSorting": [[0,'desc']],
    "aoColumnDefs": [ {
    "sClass": "center",
    "aTargets": [ -2, -3 ]
    } ]
    } );
    } );



    [/code]
  • mikeddd123mikeddd123 Posts: 6Questions: 0Answers: 0
    Would the code above be correct in this instance?
  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    As the error says - the JSON returned is invalid: http://datatables.net/faqs#json . It sounds like PHP is telling you what the error is - a reference to sEcho which is incorrect. DataTables uses GET by default, perhaps you are using _POST?

    Allan
This discussion has been closed.