i tried to paginate my json response data using jquery data table.but its not working. Using dataTables 1.10.9. My code is given below :
$(document).ready(function(){
$('#invnReport').DataTable({
"aoColumnDefs": [
{'bSortable': false, 'aTargets': [] }
]
});
});
$.ajax({
data : data,
url : url,
type : "get",
dataType: 'json',
error : function(resp) {
alert('Error');
},
success : function(resp) {
render_to_inventory(resp);
}
});
function render_to_inventory(resp){
table = '';
$.each(resp,function(indx,obj){
table += '<tr>';
table += '<td>'+parseInt(indx+1)+'</td>';
table += '<td>'+obj.Inventory.groups+'</td>';
table += '<td>'+obj.Inventory.quantity+'</td>';
});
$("tbody#invn_body").append(table);
}
here is the table
<table class="table table-striped table table-hover table table-bordered table table-condensed" id="invnReport">
<caption>
Inventory Report
</caption>
<thead >
<tr style="background:#CACACA">
<th>Sl</th>
<th>Item</th>
<th></th>
</tr>
<tr style="background:#4BB1CF">
<th style="width:4%">No</th>
<th>Name</th>
<th>Quantity</th>
</tr>
</thead>
<tbody id="invn_body">
</tbody>
</table>
here is the json response data
[
{"Inventory":{"groups":" Laptop","quantity":"1"}},
{"Inventory":{"groups":" Laptop","quantity":"1"}},
{"Inventory":{"groups":" Laptop","quantity":"2"}},
{"Inventory":{"groups":" Laptop","quantity":"1"}},
{"Inventory":{"groups":" Laptop","quantity":"-1"}},
{"Inventory":{"groups":" Laptop","quantity":"23"}},
{"Inventory":{"groups":" Laptop","quantity":"6"}},
{"Inventory":{"groups":" Laptop","quantity":"13"}},
{"Inventory":{"groups":" Laptop","quantity":"1"}},
{"Inventory":{"groups":" Laptop","quantity":"3"}},
{"Inventory":{"groups":" Laptop","quantity":"1"}},
{"Inventory":{"groups":" Laptop","quantity":"1"}}
]
its working with php data but not with json data.please help.