dataTable serverside example
by deepak Singh
HTML
<link rel="stylesheet" href="http://cdn.datatables.net/1.10.4/css/jquery.dataTables.css">
<script src="http://cdn.datatables.net/1.10.4/js/jquery.dataTables.min.js"></script>
<button id="reload">reload table</button>
<button class="toggleCols" data-column="0">First Name</button>
<br>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<div id="container"></div>
<br>
<table id="example" class="display" width="100%" cellspacing="0">
<thead>
<tr>
<th>First name</th>
<th>Last name</th>
<th>Position</th>
<th>Office</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
<tfoot>
<tr>
<th>First name</th>
<th>Last name</th>
<th>Position</th>
<th>Office</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</tfoot>
</table>
JavaScript
$(document).ready(function() {
var url = 'http://www.json-generator.com/api/json/get/cbEfqLwFaq?indent=2';
var table = $('#example').DataTable({
'processing': true,
'serverSide': true,
'ajax': {
type: 'POST',
'url': url,
'data': function(d) {
console.log(d.order);
return JSON.stringify(d);
}
},
"initComplete": function(settings, json) {
data = table.rows().data()
var categories = []; //creating array for storing browser type in array.
var series_data = [];
for (var i = 0; i < data.length; i++) {
categories.push(data[i][0])
series_data.push(Number([data[i][5].match(/\d/g).join("")]))
}
plotChart(categories, series_data)
}
});
//
//
$('#reload').click(function(e) {
table.ajax.reload();
});
//
});
function plotChart(categories, series_data) {
Highcharts.chart('container', {
chart: {
type: 'column'
},
xAxis: {
categories: categories
},
yAxis: {
title: {
text: 'Count'
}
},
series: [{
name: 'person',
data: series_data
}]
});
}