Cara Membuat Order by Pada JASON :
Code:
order: [[2, 'asc']],
Penjelasan:
warna merah itu menunjukan list table yang ingin order.
{"data": "code"},{"data": "name_country"},
fungsi order: [[1, 'asc']], berdasarkan = code
fungsi order: [[2, 'asc']], berdasarkan = name_country
Full code:
<script type="text/javascript">
$(document).ready(function() {
$.fn.dataTableExt.oApi.fnPagingInfo = function(oSettings)
{
return {
"iStart": oSettings._iDisplayStart,
"iEnd": oSettings.fnDisplayEnd(),
"iLength": oSettings._iDisplayLength,
"iTotal": oSettings.fnRecordsTotal(),
"iFilteredTotal": oSettings.fnRecordsDisplay(),
"iPage": Math.ceil(oSettings._iDisplayStart / oSettings._iDisplayLength),
"iTotalPages": Math.ceil(oSettings.fnRecordsDisplay() / oSettings._iDisplayLength)
};
};
var t = $("#mytable").dataTable({
initComplete: function() {
var api = this.api();
$('#mytable_filter input')
.off('.DT')
.on('keyup.DT', function(e) {
if (e.keyCode == 13) {
api.search(this.value).draw();
}
});
},
oLanguage: {
sProcessing: "loading..."
},
processing: true,
serverSide: true,
ajax: {"url": "ref_country/json", "type": "POST"},
columns: [
{
"data": "id_country",
"orderable": false
},{"data": "code"},{"data": "name_country"},
{
"data" : "action",
"orderable": false,
"className" : "text-center"
}
],
order: [[2, 'asc']],
rowCallback: function(row, data, iDisplayIndex) {
var info = this.fnPagingInfo();
var page = info.iPage;
var length = info.iLength;
var index = page * length + (iDisplayIndex + 1);
$('td:eq(0)', row).html(index);
}
});
});
</script>
No comments:
Post a Comment