Adding links to record field
Adding links to record field
I'm using Datatables to create an archive of comics my client is creating, and would like the title of the comic to be a link to that comic.
Initialize:
[code]
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"sAjaxSource": "archive/archive.txt"
} );
} );
[/code]
HTML:
[code]
Author
Title
Episode
Date
Tags
[/code]
JSON:
[code]
{ "aaData": [
["Bob","Title One","Episode 1","9/30/2010","tag1,tag2,tag3"],
["Bob","Title One","Episode 2","10/2/2010","tag1,tag2,tag3"],
["Bob","Title One","Episode 3","10/4/2010","tag1,tag2,tag3"],
["Bob","Title Four","Episode 1","10/8/2010","tag1,tag2,tag3"],
["Bob","Title Five","Episode 1","10/11/2010","tag1,tag2,tag3"],
["Bob","Title Six","Episode 1","10/12/2010","tag1,tag2,tag3"],
["Kevin","Title Seven","Episode 1","10/15/2010","tag1,tag2,tag3"],
["Kevin","Title Eight","Episode 1","10/17/2010","tag1,tag2,tag3"],
["Kevin","Title Eight","Episode 2","10/20/2010","tag1,tag2,tag3"],
["Kevin","Title Ten","Episode 1","10/22/2010","tag1,tag2,tag3"],
["Kevin","Title Eleven","Episode 1","10/23/2010","tag1,tag2,tag3"],
["Kevin","Title Twelve","Episode 1","10/24/2010","tag1,tag2,tag3"]
] }
[/code]
Web page:
http://www.classicalmusicisboring.com/archive.html
Thanks.
Initialize:
[code]
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"sAjaxSource": "archive/archive.txt"
} );
} );
[/code]
HTML:
[code]
Author
Title
Episode
Date
Tags
[/code]
JSON:
[code]
{ "aaData": [
["Bob","Title One","Episode 1","9/30/2010","tag1,tag2,tag3"],
["Bob","Title One","Episode 2","10/2/2010","tag1,tag2,tag3"],
["Bob","Title One","Episode 3","10/4/2010","tag1,tag2,tag3"],
["Bob","Title Four","Episode 1","10/8/2010","tag1,tag2,tag3"],
["Bob","Title Five","Episode 1","10/11/2010","tag1,tag2,tag3"],
["Bob","Title Six","Episode 1","10/12/2010","tag1,tag2,tag3"],
["Kevin","Title Seven","Episode 1","10/15/2010","tag1,tag2,tag3"],
["Kevin","Title Eight","Episode 1","10/17/2010","tag1,tag2,tag3"],
["Kevin","Title Eight","Episode 2","10/20/2010","tag1,tag2,tag3"],
["Kevin","Title Ten","Episode 1","10/22/2010","tag1,tag2,tag3"],
["Kevin","Title Eleven","Episode 1","10/23/2010","tag1,tag2,tag3"],
["Kevin","Title Twelve","Episode 1","10/24/2010","tag1,tag2,tag3"]
] }
[/code]
Web page:
http://www.classicalmusicisboring.com/archive.html
Thanks.
This discussion has been closed.
Replies
Allan
I don't suppose I understand. Might you show me an example from my data? I tried this:
[code]["Bob",link,"Episode 1","9/30/2010","tag1,tag2,tag3"],[/code]
Which, of course, didn't work.
Further, while having read the bit about fnRender, I'm not quite sure how to use it.
Adam
[code]
["Bob",'link',"Episode 1","9/30/2010","tag1,tag2,tag3"],
[/code]
Allan
[code]
{ "aaData": [
["Bob",'link',"Episode 1","9/30/2010","tag1,tag2,tag3"],
] }
[/code]
I got back an alert: DataTables warning: JSON data from server failed to load or be parsed. This is most likely to be caused by a JSON formatting error.
[code]
{ "aaData": [
["Bob","link","Episode 1","9/30/2010","tag1,tag2,tag3"],
] }
[/code]
Allan
I am pulling my data directly from my sql database using the default functions given in the server side processing php code. I am also trying to add a link just like bigsilk was. I see how he did it since he made his own array instead of grabbing his data from a database but I am lost on how to do this with pulled data from my db?
I would apprecaite it if you could point me in the right direction or offer an example. Thank you very much!
Allan
Thanks for the quick response. I apprecaite it. I will play around with it and see if I can figure out how to make them links with their id attached to each link. Thanks again man.
I guess my question is where I need to put the foreach or how I tell it to grab a new report_ID after each iteration.
[code]
//aaData is the array where the data from the database is pulled into
$bll = new Bll();
$arrNames = $bll -> getReports();
foreach ($arrNames as $reportID){
$id = $bll->getIdByName($reportID);
$reportID = $bll->getReportIDbyId($id);
}
$sOutput .= '"aaData": [ ';
while ( $aRow = mysql_fetch_array( $rResult ) )
{
$sOutput .= "[";
for ( $i=0; $i < count($aColumns); $i++ )
{
if ( $aColumns[$i] == "report_ID")
{
/* Special output formatting for 'report_id' Create the links*/
$sOutput .= ($aRow[ $aColumns[$i] ] != "0") ?
'"'.$reportID.'",' :
'"'.str_replace('"', '\"', $aRow[ $aColumns[$i] ]).'",';
}
else if ( $aColumns[$i] != ' ' )
{
/* General output */
$sOutput .= '"'.str_replace('"', '\"', $aRow[ $aColumns[$i] ]).'",';
}
}
[/code]
Thank you for any help.
Allan
Funny how you work on things for an hour or so then the next day you figure it out in 15 minutes.
Thank you again, Have a great day.