Last active
December 10, 2015 22:38
-
-
Save jtarleton/4503930 to your computer and use it in GitHub Desktop.
Basic datatables ajax implementation w/ JSON
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script type="text/javascript" src="datatables.js"></script> | |
</head> | |
<div class="well box"> | |
<table id="example"> | |
<thead> | |
<tr><th>id</th><th>name</th></tr> | |
</thead> | |
<tfoot> | |
<tr><th></th><th></th></tr> | |
</tfoot> | |
</table> | |
</div> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
jQuery(document).ready(function(){ | |
jQuery('#example').dataTable({ | |
"sScrollY" : "420px", | |
"aaSorting" : [[ 1, "desc" ]], | |
"bPaginate" : true, | |
"bDeferRender" : false, | |
"bScrollAutoCss" : true, | |
"bScrollCollapse" : true, | |
"bStateSave" : true, | |
"bProcessing" : true, | |
"sPaginationType" : "full_numbers", | |
"iDisplayLength" : 100, | |
"bServerSide" : false, | |
"sAjaxSource" : "http://www.domain.com/json_out.php", | |
"fnInitComplete" : function(oSettings, json) { | |
}, | |
"aoColumns" : [ | |
{ "mData" : "_id" }, | |
{ "mData" : "name" }, | |
], | |
"oLanguage" : { | |
"sSearch" : "Filter across all data:" | |
} | |
}); | |
}); | |
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
http://www.datatables.net/ | |
*/ | |
class DataTableCallbackMaker | |
{ | |
static public function getJSON($input) | |
{ | |
$output = array(); | |
$cols = array('_id','name'); | |
for($i =0;$i<3;$i++) | |
{ | |
foreach($cols as $col) | |
$output['aaData'][$i][$col] = "Row $i"; | |
} | |
return json_encode($output); | |
} | |
} | |
$input = $_GET; | |
DataTableCallbackMaker::getJSON($input); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment