Hello all,
I could not find the answer to this question yet, so I tried creating it myself.
Although I'm slowly progressing toward a working goal, I feel like I'm re-inventing the wheel every line of code I write ...
So, in short:
would someone has a working code of datatable that reads data from a (rather large) CSV file on server side ? (rather large is 14.000 lines => my browser can't handle that much in DOM - the server can quite easily handle a parsing of that file every so often).
what I want:
using the basic zero-config example:
From there, I would need a working "read_csv.php" that obviously outputs a JSON format.
WARNING: I'm still new to datatables, so maybe I've got it all wrong, so let me know in that case ;)
note:
just to show I was not lazy and did the start of my homework: I've already got the basics working with the below content of read_csv.php, but as I was saying, I feel like re-doing stuff that has probably been done countless of times ... and doing it in a not-so-good way:
I could not find the answer to this question yet, so I tried creating it myself.
Although I'm slowly progressing toward a working goal, I feel like I'm re-inventing the wheel every line of code I write ...
So, in short:
would someone has a working code of datatable that reads data from a (rather large) CSV file on server side ? (rather large is 14.000 lines => my browser can't handle that much in DOM - the server can quite easily handle a parsing of that file every so often).
what I want:
using the basic zero-config example:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "read_csv.php"
} );
} );
</SCRIPT>
From there, I would need a working "read_csv.php" that obviously outputs a JSON format.
WARNING: I'm still new to datatables, so maybe I've got it all wrong, so let me know in that case ;)
note:
just to show I was not lazy and did the start of my homework: I've already got the basics working with the below content of read_csv.php, but as I was saying, I feel like re-doing stuff that has probably been done countless of times ... and doing it in a not-so-good way:
<?
/*
* Paging
*/
$iDisplayStart = 0;
$iDisplayLength = 9;
if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' ) {
$iDisplayStart = $_GET['iDisplayStart'];
$iDisplayLength = $_GET['iDisplayLength'];
}
$iDisplayEnd = $iDisplayStart + $iDisplayLength;
$myFile = "/prod/backup/OSS/NE_DATA/NE_DATA.csv";
$myFile_data = file($myFile);
$count = 0;
$echo_block = "";
foreach ($myFile_data as &$line) {
$line = chop($line);
$line = addslashes($line);
list($VENDOR,$EM,$NETWORK,$NE_NAME,$TYPE,$VERSION,$MAA,$MAC,$NSEL,$ON_IDN,$COMMENTS,$EM_IP,$NE_IP,$GNE,$HD1,$HD2,$Region,$Country) = explode(",",$line);
$echo_line = "[ \"$VENDOR\", \"$EM\", \"$NETWORK\", \"$NE_NAME\", \"$TYPE\", \"$VERSION\", \"$MAA\", \"$MAC\", \"$NSEL\", \"$ON_IDN\", \"$COMMENTS\", \"$EM_IP\", \"$NE_IP\", \"$GNE\", \"$HD1\", \"$HD2\", \"$Region\", \"$Country\" ],";
$count++;
if ( $count > $iDisplayStart && $count < $iDisplayEnd ) {
$echo_block .= $echo_line;
}
}
$echo_block = substr_replace($echo_block,"",-1);
# add the header:
$echo_block = "{
\"sEcho\": ".$_GET['sEcho'].",
\"iTotalRecords\": \"14535\",
\"iTotalDisplayRecords\": \"14535\",
\"aaData\": [
".$echo_block;
echo "$echo_block ] }";
?>
so i've got the paging done, and the real stuff will only start with filtering and ordering...