Process data before displaying it

Process data before displaying it

nocracknocrack Posts: 5Questions: 0Answers: 0
edited January 2011 in General
Hi,

I was wondering if there is any simple way to do some data processing before you actually display the table.

Basically, I'm using the server side processing and get my stuff from a database.
One of the field that comes back is actually a table. As it is, the data are pulled from the DB, so it displays a table in 1 field (i.e [1, 2, 3, 4] ).
What I need to achieve is to extract the first line of that table (1), and display this one, then use the table to do some other stuff with it. (actually using it on show/hide thingy)

I hope it makes sense.

Cheers!

Replies

  • nocracknocrack Posts: 5Questions: 0Answers: 0
    Hi,

    No one can give me some help?
    I'd really appreciate at least some direction, that would be much appreciated!

    Thanks!
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Sounds like fnServerData would be the right place to do this: http://datatables.net/examples/server_side/custom_vars.html . You can do post (or pre- depending on your outlook!) processing of the server return there. You could make an array of the information you want displayed in the table and give that to DataTables - a reference to the data would be needed as well so you can refer to it when displaying the details row.

    Allan
  • nocracknocrack Posts: 5Questions: 0Answers: 0
    Hi Allan,

    Thank you for the help.
    I guess I have to modify/get the aoData table to do my stuff. Am I right?
    Also, (sorry I'm a real newbie), this is a table of object so I can't work on it straight away. How can I find and change what I need in it?

    Many Thanks,
    Arnaud
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    I doubt you need to modify aoData at all - you will need to modify the aaData which is returned from the server though. I'd suggest as a first step getting the server-side processing working and then modifying the return to match what is needed in the table display. Once that is done, you can move on to the more complex part of getting the 'details' row to work.

    Allan
  • nocracknocrack Posts: 5Questions: 0Answers: 0
    edited January 2011
    The server side processing is all done. I call a php script that takes data from a sqlite db.
    It returns me about 20 things per row. I display about 7 of it per lines on the table and the rest is showed on the show/hide part.
    All that stuff is working.
    The only part left to do for me is to get that table into different variables that I reuse (one of it being displayed in one of the column of the table).

    Here is my code:
    [code]
    /* Formating function for row details */
    function fnFormatDetails ( nTr ) {
    var aData = oTable.fnGetData( nTr );

    dIPlist = aData[3].slice(1,aData[3].length-1);
    var dIPlist = dIPlist.split(',');

    for(j = 19; j <= 21; j++){
    if (aData[j] == 0) {
    aData[j]="No";
    } else {
    aData[j]="Yes";
    }
    }

    var sOut = '';
    sOut += ' ';
    sOut += ' Memory:'+aData[11]+' Gb ';
    sOut += ' IP addresses:';

    for(i = 0; i < dIPlist.length; i++){
    sOut += dIPlist[i]+'
    ';
    }

    sOut += '  ';
    sOut += ' External IPs:  ';
    sOut += ' Backed up:'+aData[20]+' ';
    sOut += ' CC Doclink ';
    sOut += ' Comments:'+aData[25]+'';
    sOut += ' ';
    ...
    sOut += ' ';
    sOut += ' CPU core:'+aData[17]+'';
    sOut += '    ';
    sOut += '    ';
    sOut += ' Comissionned:'+aData[18]+' ';
    sOut += '    ';
    result = aData[6].indexOf('Windows');
    if (result == -1) {
    sOut += 'Kernel:'+aData[10]+'';
    } else {
    sOut += '  ';
    }
    sOut += ' ';
    sOut += '';

    return sOut;
    }

    $(document).ready(function() {
    /* Build the DataTable with third column using our custom sort functions */
    oTable = $('#example').dataTable( {
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "../getdata.php",
    "bServerSide": "<?php echo $option ?>",
    "bJQueryUI": true,
    "bLengthChange": true,
    "bSortClasses": false,
    "sPaginationType": "full_numbers",
    "aaSorting": [ [2,'asc'] ],
    "aoColumns": [
    { "sClass": "center", "bSortable": false},
    null,
    null,
    null,
    { "sType": 'string-case' },
    { "sClass": "center" },
    null,
    null,
    null,
    null,
    { "bVisible": false },
    { "bVisible": false },
    { "bVisible": false },
    { "bVisible": false },
    { "bVisible": false },
    { "bVisible": false },
    { "bVisible": false },
    { "bVisible": false },
    { "bVisible": false },
    { "bVisible": false },
    { "bVisible": false },
    { "bVisible": false },
    { "bVisible": false },
    { "bVisible": false },
    { "bVisible": false },
    { "bVisible": false },
    { "bVisible": false },
    { "bVisible": false },
    { "bVisible": false }
    ],
    "fnServerData": function ( sSource, aoData, fnCallback ) {
    /* Add some extra data to the sender */
    $.getJSON( sSource, aoData, function (json) {
    // not sure what to do here
    fnCallback(json)
    } );
    }


    } );

    } );

    $('#example tbody td img').live( 'click', function () {
    var nTr = this.parentNode.parentNode;
    if ( this.src.match('details_close') ) {
    /* This row is already open - close it */
    this.src = "images/details_open.png";
    oTable.fnClose( nTr );
    } else {
    /* Open this row */
    this.src = "images/details_close.png";
    oTable.fnOpen( nTr, fnFormatDetails(nTr), 'details' );
    }
    } );

    function toggle() {
    var ele = document.getElementById("toggleText");
    var mytable = document.getElementById("example_wrapper");
    if(ele.style.display == "block") {
    ele.style.display = "none";
    mytable.style.zIndex = "1";
    }
    else {
    ele.style.display = "block";
    mytable.style.zIndex = "-1";
    }
    }
    [/code]

    Thanks for helping Allan, this is very much appreciated!
  • nocracknocrack Posts: 5Questions: 0Answers: 0
    I think I found what I needed!

    mytable = json.aaData[i][5];

    I should be able to do the rest myself now thanks for the help !!!
This discussion has been closed.