How do I add html to my server processed table?

How do I add html to my server processed table?

BlalienBlalien Posts: 17Questions: 0Answers: 0
edited May 2010 in General
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]

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    The JSOn created by your code isn't going to be valid there - you've got unescaped double quotes in the HTML which will terminate the string prematurely.

    http://jsonlint.com will help for validating your returned JSON. But just add the slashes and it should be good to go.

    Allan
  • BlalienBlalien Posts: 17Questions: 0Answers: 0
    Thanks Allan,

    It is fully functional now! And off course a lot faster thanks to the server side processing.

    Greetings,
    Blalien
  • BlalienBlalien Posts: 17Questions: 0Answers: 0
    edited May 2010
    Is there a way to let the page jump to a row?
    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
  • BlalienBlalien Posts: 17Questions: 0Answers: 0
    I am also working on a table with a looped thead. Is there something that I can use to loop the aoColumns?

    Thanks,
    Blalien
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    1. Jump to a row: http://datatables.net/plug-ins/api#fnDisplayRow

    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
  • BlalienBlalien Posts: 17Questions: 0Answers: 0
    Thanks for the answers.

    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
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Oh I see - you can just create a Javascript object in your loop and use that for the aoColumns array I guess. That assumes you want to create an aoColumns array at the same time thought.

    Allan
  • BlalienBlalien Posts: 17Questions: 0Answers: 0
    I found it just before a read your comment and was working on that, but I don't see where to put the loop. Do you have any suggestions?

    [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]
  • BlalienBlalien Posts: 17Questions: 0Answers: 0
    Got it to work with a PHP while loop!
    Feel like an idiot ;).

    Thanks,
    Blalien
This discussion has been closed.