How do I add html to my server processed table?
How do I add html to my server processed table?
I am trying to add html to my server processed table, but nothing is working.
Can anybody help me with this?
Here is the code I am using.
[code]
$sOutput = '{';
$sOutput .= '"sEcho": '.intval($_GET['sEcho']).', ';
$sOutput .= '"iTotalRecords": '.$iTotal.', ';
$sOutput .= '"iTotalDisplayRecords": '.$iFilteredTotal.', ';
$sOutput .= '"aaData": [ ';
while ( $aRow = mysql_fetch_array( $rResult ) )
{
$sOutput .= "[";
$sOutput .= '"'.addslashes($aRow['cus_abbreviation']).'",';
$sOutput .= '"'.addslashes($aRow['cus_name']).'",';
$sOutput .= '"'.addslashes($aRow['cus_ig']).'",';
$sOutput .= '"'.addslashes($aRow['cus_active']).'",';
$sOutput .= '"",'; // Needs to contain html, php and css
$sOutput .= "],";
}
$sOutput = substr_replace( $sOutput, "", -1 );
$sOutput .= '] }';
echo $sOutput;
function fnColumnToField( $i )
{
if ( $i == 0 )
return "cus_abbreviation";
else if ( $i == 1 )
return "cus_name";
else if ( $i == 2 )
return "cus_ig";
else if ( $i == 3 )
return "cus_active";
}
[/code]
Can anybody help me with this?
Here is the code I am using.
[code]
$sOutput = '{';
$sOutput .= '"sEcho": '.intval($_GET['sEcho']).', ';
$sOutput .= '"iTotalRecords": '.$iTotal.', ';
$sOutput .= '"iTotalDisplayRecords": '.$iFilteredTotal.', ';
$sOutput .= '"aaData": [ ';
while ( $aRow = mysql_fetch_array( $rResult ) )
{
$sOutput .= "[";
$sOutput .= '"'.addslashes($aRow['cus_abbreviation']).'",';
$sOutput .= '"'.addslashes($aRow['cus_name']).'",';
$sOutput .= '"'.addslashes($aRow['cus_ig']).'",';
$sOutput .= '"'.addslashes($aRow['cus_active']).'",';
$sOutput .= '"",'; // Needs to contain html, php and css
$sOutput .= "],";
}
$sOutput = substr_replace( $sOutput, "", -1 );
$sOutput .= '] }';
echo $sOutput;
function fnColumnToField( $i )
{
if ( $i == 0 )
return "cus_abbreviation";
else if ( $i == 1 )
return "cus_name";
else if ( $i == 2 )
return "cus_ig";
else if ( $i == 3 )
return "cus_active";
}
[/code]
This discussion has been closed.
Replies
http://jsonlint.com will help for validating your returned JSON. But just add the slashes and it should be good to go.
Allan
It is fully functional now! And off course a lot faster thanks to the server side processing.
Greetings,
Blalien
And is there a way to assign a different class to a td or tr?
I also have one problem.
The page of the table is saved, but it doesn't load that page. It loads the first page when I return to the table.
[code]
var oTable;
var asInitVals = new Array();
$(document).ready(function() {
oTable = $('#tableCM').dataTable( {
"bProcessing": true,
"bServerSide": true,
"bStateSave": true,
"sPaginationType": "full_numbers",
"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
var this_class = "no_change";
if ( aData[0] == "<?php echo $jump;?>" )
{
this_class = "changed";
}
nRow.className = nRow.className + " " + this_class;
return nRow;
},
"sAjaxSource": "includes/server_processing_cm.php",
"oLanguage": {
"sSearch": "Zoek in alle kolommen:",
"sLengthMenu": "Toon _MENU_ resultaten per pagina",
"sZeroRecords": "Geen resulaten gevonden.",
"sInfo": "Toon _START_ tot _END_ van _TOTAL_ resultaten",
"sInfoEmtpy": "Toon 0 tot 0 van 0 resultaten",
"sInfoFiltered": "(gefilterd uit _MAX_ resultaten)",
"oPaginate": {
"sFirst": "Begin",
"sLast": "Eind",
"sNext": "Volgende",
"sPrevious": "Vorige"
}
},
"aoColumns": [
{ "bSearchable": false, "bVisible": false, "sWidth": "10%" },
{ "sWidth": "10%" },
{ "sWidth": "50%" },
{ "sType": "html", "sWidth": "10%" },
{ "sType": "html", "sWidth": "10%" },
{"bSearchable": false, "bSortable": false, "sWidth": "10%" },
{"bSearchable": false, "bSortable": false, "sWidth": "10%" }
]
} );
} );
[/code]
Thanks,
Blalien
Thanks,
Blalien
2. I think that's a bug in DataTables. I think that this thread covers it: http://datatables.net/forums/comments.php?DiscussionID=1523#Item_7 . If you can wait a day or two I hope to release DataTables 1.7 beta which will address this.
3. A looped thead? Not sure I quite follow. aoColumns is just an array of all the column headers.
Allan
I have a while loop for the thead to print the headers. And I need to assign aoColumns to these TH's in thead. Without these the table doesn't function properly.
[code]
Klanten
<?php
$groups = mysql_query("SELECT * FROM internalgroup");
while($group = mysql_fetch_assoc($groups))
{
echo '' . $group['ig_abbreviation'] . '';
}
?>
[/code]
Thanks,
Blalien
Allan
[code]
var i=1;
for (i=1;i<<?php echo $num_rows; ?>;i++)
{
//document.write("The number is " + i);
//document.write("
");
{"bSearchable": false, "bSortable": false, "sWidth": "5%", "sClass": "center" },
//Code that needs to be looped
}
var oTable;
var asInitVals = new Array();
$(document).ready(function() {
oTable = $('#tableCG').dataTable( {
"bProcessing": true,
"bServerSide": true,
"bStateSave": true,
"sPaginationType": "full_numbers",
"sAjaxSource": "includes/server_processing_cg.php",
"oLanguage": {
"sSearch": "Zoek in alle kolommen:",
"sLengthMenu": "Toon _MENU_ resultaten per pagina",
"sZeroRecords": "Geen resulaten gevonden.",
"sInfo": "Toon _START_ tot _END_ van _TOTAL_ resultaten",
"sInfoEmtpy": "Toon 0 tot 0 van 0 resultaten",
"sInfoFiltered": "(gefilterd uit _MAX_ resultaten)",
"oPaginate": {
"sFirst": "Begin",
"sLast": "Eind",
"sNext": "Volgende",
"sPrevious": "Vorige"
},
"aoColumns": [
//Loop needs to be here
{"bSearchable": false, "bSortable": false, "sWidth": "5%", "sClass": "center" }
]
}
} );
} );
Thanks,
Blalien
[/code]
Feel like an idiot ;).
Thanks,
Blalien