How to add hyperlink to each row in Datatable?
How to add hyperlink to each row in Datatable?
jerry98225
Posts: 10Questions: 0Answers: 0
I already searched the forum and found some similar posts, but I still can't figure out how to do this. Hope someone can help me out.
I am trying to add links for all the rows that generate data from database in Datatable.I tried the code below but it won't work. Datatable just ignore the tag i created for . Anyone can help? Thanks a lot.
below is the view file for my application
<?php foreach ($result as $row):?>
//the link to the search controller to get detailed information of each row
<?= $row->job_number; ?>
<?= $row->city; ?>
<?= (empty($row->street_number))? 'N/A':$row->street_number;?>
<?= $row->street;?>
<?= $row->map;?>
<?php endforeach; ?>
I am trying to add links for all the rows that generate data from database in Datatable.I tried the code below but it won't work. Datatable just ignore the tag i created for . Anyone can help? Thanks a lot.
below is the view file for my application
<?php foreach ($result as $row):?>
//the link to the search controller to get detailed information of each row
<?= $row->job_number; ?>
<?= $row->city; ?>
<?= (empty($row->street_number))? 'N/A':$row->street_number;?>
<?= $row->street;?>
<?= $row->map;?>
<?php endforeach; ?>
This discussion has been closed.
Replies
Allan
Alternatively try <?php echo $row->job_number;?> instead of <?= $row->job_number;?>.
What i'm trying to do now is just add a column with a hyperlink containing data from let say first column. I have got 3 columns: invoiceNo, data, time and I would like to add the fourth one containing the hyperlink like a . What is the simplest way to do this?
That's my code for the table:
[code]
$(document).ready(function() {
$('#tab1').dataTable( {
"bProcessing": true,
"bServerSide": true,
"iDisplayLength": 25,
"sAjaxSource": "?q=table/1"
} );
} );
[/code]
[code]
/*
* Script: DataTables server-side script for PHP and MySQL
* Copyright: 2010 - Allan Jardine
* License: GPL v2 or BSD (3-point)
*/
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Easy set variables
*/
/* Array of database columns which should be read and sent back to DataTables. Use a space where
* you want to insert a non-database field (for example a counter or static image)
*/
$aColumns = array( 'invoiceNo', 'date', 'time' );
/* Indexed column (used for fast and accurate table cardinality) */
$sIndexColumn = "id";
/* DB table to use */
$sTable = "invoices";
/* Database connection information */
$gaSql['user'] = "***";
$gaSql['password'] = "***";
$gaSql['db'] = "db1";
$gaSql['server'] = "localhost";
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* If you just want to use the basic configuration for DataTables with PHP server-side, there is
* no need to edit below this line
*/
/*
* MySQL connection
*/
$gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) or
die( 'Could not open connection to server' );
mysql_select_db( $gaSql['db'], $gaSql['link'] ) or
die( 'Could not select database '. $gaSql['db'] );
/*
* Paging
*/
$sLimit = "";
if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' )
{
$sLimit = "LIMIT ".mysql_real_escape_string( $_GET['iDisplayStart'] ).", ".
mysql_real_escape_string( $_GET['iDisplayLength'] );
}
/*
* Ordering
*/
if ( isset( $_GET['iSortCol_0'] ) )
{
$sOrder = "ORDER BY ";
for ( $i=0 ; $i $iFilteredTotal,
"aaData" => array()
);
while ( $aRow = mysql_fetch_array( $rResult ) )
{
$row = array();
for ( $i=0 ; $i
1. Use fnRender on the client-side
2. Add a condition where my " /* Special output formatting for 'version' column */" comment is to add link formatting.
Allan
Ok, so I added this to the initialisation part:
[code]
"aoColumnDefs": [
{
"fnRender": function ( oObj ) {
return 'SomeLink';
},
"aTargets": [ 3 ]
}
]
[/code]
becouse i want to put the link into the fourth column. I also added a column to the html table:
[code]
invoiceNo
date
time
link
Ładowanie danych z serwera...
invoiceNo
date
time
link
[/code]
and i got the error:
[quote]
DataTables warning (table id = 'example'): Requested unknown parameter '3' from the data source for row 0
[/quote]
it works but displaying this error. My server side script is sending just 3 columns.. the fourth one should be build using the data from the first one.
WHAT should I do to avoid this kind of error?
The easiest way to deal with this is to give it a default value with sDefaultContent . Just give it an empty string.
Allan
regards,
david.