DataTables with AJAX
HTML
<script src="http://datatables.net/release-datatables/media/js/jquery.dataTables.js"></script>
<link rel="stylesheet" href="http://datatables.net/release-datatables/media/css/demo_table.css">
<script src="http://vitalets.github.com/x-editable/assets/mockjax/jquery.mockjax.js"></script>
<link rel="stylesheet" href="http://cdn.datatables.net/1.10.1/css/jquery.dataTables.css">
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css">
<script src="http://cdn.datatables.net/1.10.1/js/jquery.dataTables.min.js"></script>
<table id="test" class="display" cellspacing="0">
<thead><tr><th>select</th><th>opeartion</th></tr></thead>
<tbody>
</tbody>
</table>
JavaScript
//ajax emulation
$.mockjax({
url: '/test/0',
responseTime: 200,
responseText: {aaData: [ [{"chk":"on"}, {"operation":["Modify", "Delete"]}],
[{"chk":"on"}, {"operation":["Modify", "Delete"]}] ,
[{"chk":"on"}, {"operation":["Modify", "Delete"]}] ,
[{"chk":"on"}, {"operation":["Modify", "Delete"]}] ,
[{"chk":"on"}, {"operation":["Modify", "Delete"]}] ,
[{"chk":"on"}, {"operation":["Modify", "Delete"]}] ,
[{"chk":"on"}, {"operation":["Modify", "Delete"]}]
] }
});
var $table = $('#test');
$table.dataTable( {
"lengthMenu": [[2,25,50 ,100, -1], [2,25,50, 100, "All"]],
"sPaginationType": "full_numbers" ,
"paging": true,
"ordering" : true,
"scrollY":false,
"autoWidth": false,
"serverSide": false,
"processing": false,
"info": true ,
"bDeferRender": true, "bProcessing": true, "sAjaxSource": "/test/0",
fnRowCallback : function(nRow, aaData, iDisplayIndex) {
jQuery('td:eq(0)', nRow).html('<input name="chk" type="checkbox">');
operationString ='<select name="select"><option>'+ aaData[1].operation[0] +
'</option>';
operationString=operationString+'<option>'+ aaData[1].operation[1] + '</option>';
operationString = operationString+ '</select>';
jQuery('td:eq(1)', nRow).html(operationString);
return nRow;
},
} );