The column sorting doesn't work
The column sorting doesn't work
haishi633
Posts: 2Questions: 0Answers: 0
Hello, guys
The below is my code portion. There are 6 columns in the table, the php file extracts 4 columns from db table, it work well, but If i uncomment the aaSorting": [[2,'desc'], [5,'asc']], it doesn't work , i am new to datatables, is anybody can help me?
[code]
$(document).ready(function(){
var oTable = $('#example').dataTable({
//"sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
"sPaginationType": "bootstrap",
"sDom": "<'row'<'span7'l><'span7'f>r>t<'row'<'span7'i><'span7'p>>",
"bProcessing": true,
"bServerSide": true,
"bPaginate": true,
"sAjaxSource": "showHistoryLog.php",
"iDisplayLength": 20,
"aLengthMenu": [[20, 30, 50, -1], [20, 30, 50, "All"]],
"fnServerParams": function (aoData) {
aoData.push( { "name":"pid","value":$('#pid').val()} );
aoData.push( { "name":"tid","value":$('#tid').val()} );
},
//"aaSorting": [[2,'desc'], [5,'asc']],
"oLanguage": {
"sLengthMenu": "_MENU_ records per page"
},
"aoColumns": [
//{"mData": null,"sDefaultContent":$('#tname').val()},
// {"mData": null,"sDefaultContent":$('#pname').val()},
{"mData": null,"sDefaultContent":$('#tname').val()},
{"mData": null,"sDefaultContent":$('#pname').val()},
{"mData": "log_date"},
{"mData": "log_flag"},
{"mData": "log_content"},
{"mData": "pod_name"}
]
});
});
[/code]
showHistoryLog.php
[code]...
$aColumns = array( 'l.log_flag','l.log_date','l.log_content','f.pod_name');
....
[/code]
This bellow is used to show the table
[code]..........
Test ItemTest PlanLog TimeStatusContentLocation
Loading data from server
Test ItemTest PlanLog TimeStatusContentLocation
..........
[/code]
The below is my code portion. There are 6 columns in the table, the php file extracts 4 columns from db table, it work well, but If i uncomment the aaSorting": [[2,'desc'], [5,'asc']], it doesn't work , i am new to datatables, is anybody can help me?
[code]
$(document).ready(function(){
var oTable = $('#example').dataTable({
//"sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
"sPaginationType": "bootstrap",
"sDom": "<'row'<'span7'l><'span7'f>r>t<'row'<'span7'i><'span7'p>>",
"bProcessing": true,
"bServerSide": true,
"bPaginate": true,
"sAjaxSource": "showHistoryLog.php",
"iDisplayLength": 20,
"aLengthMenu": [[20, 30, 50, -1], [20, 30, 50, "All"]],
"fnServerParams": function (aoData) {
aoData.push( { "name":"pid","value":$('#pid').val()} );
aoData.push( { "name":"tid","value":$('#tid').val()} );
},
//"aaSorting": [[2,'desc'], [5,'asc']],
"oLanguage": {
"sLengthMenu": "_MENU_ records per page"
},
"aoColumns": [
//{"mData": null,"sDefaultContent":$('#tname').val()},
// {"mData": null,"sDefaultContent":$('#pname').val()},
{"mData": null,"sDefaultContent":$('#tname').val()},
{"mData": null,"sDefaultContent":$('#pname').val()},
{"mData": "log_date"},
{"mData": "log_flag"},
{"mData": "log_content"},
{"mData": "pod_name"}
]
});
});
[/code]
showHistoryLog.php
[code]...
$aColumns = array( 'l.log_flag','l.log_date','l.log_content','f.pod_name');
....
[/code]
This bellow is used to show the table
[code]..........
Test ItemTest PlanLog TimeStatusContentLocation
Loading data from server
Test ItemTest PlanLog TimeStatusContentLocation
..........
[/code]
This discussion has been closed.
Replies
Also note that sine you are using server-side processing, it is the server which is doing the sorting (your `showHistoryLog.php`, not DataTables) - so if multi-column sorting isn't working, it is because it hasn't been implemented in that script.
> Also I want to know if the number of columns from json must be equal to the number of the table columns?
When using arrays - yes. You can use objects to overcome this: http://datatables.net/blog/Extended_data_source_options_with_DataTables
Allan