Process data before displaying it
Process data before displaying it
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!
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!
This discussion has been closed.
Replies
No one can give me some help?
I'd really appreciate at least some direction, that would be much appreciated!
Thanks!
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
Allan
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!
mytable = json.aaData[i][5];
I should be able to do the rest myself now thanks for the help !!!