Sorting only by visible columns
Sorting only by visible columns
datatableusers
Posts: 2Questions: 0Answers: 0
I probably read almost every thread I could find here but still did not succeed to solve my issue. I hope I am not missing anything obvious :)
I implemented Server-Side rendering. I am showing only 5 columns while the response contains 6 columns. I am using 1 column to render one table column. As such for example when I click on the 4th column it sorts by the 3rd column. I understand I can do something with fnVisibleToColumnIndex but I did not understand where and how I put it.
My jquery:
[code]
$(document).ready(function() {
$('#tablesorter').dataTable({
"sPaginationType": "full_numbers",
"aaSorting": [[ 4, "asc" ]],
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "query.php",
"aoColumns": [
{
"mRender": function ( data, type, row ) {
return '';
},
"aTargets": [ 0 ]
},
{ "mData": 2 },
{ "mData": 3 },
{ "mData": 4 },
{ "mData": 5 }
]
});
} );
[/code]
If I understand correctly all I need to do is to implement the following:
[code]
$.fn.dataTableExt.oApi.fnVisibleToColumnIndex = function ( oSettings, iMatch )
{
return oSettings.oApi._fnVisibleToColumnIndex( oSettings, iMatch );
};
[/code]
I would appreciate any hint on where and how should I put it if it is the right direction at all.
I implemented Server-Side rendering. I am showing only 5 columns while the response contains 6 columns. I am using 1 column to render one table column. As such for example when I click on the 4th column it sorts by the 3rd column. I understand I can do something with fnVisibleToColumnIndex but I did not understand where and how I put it.
My jquery:
[code]
$(document).ready(function() {
$('#tablesorter').dataTable({
"sPaginationType": "full_numbers",
"aaSorting": [[ 4, "asc" ]],
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "query.php",
"aoColumns": [
{
"mRender": function ( data, type, row ) {
return '';
},
"aTargets": [ 0 ]
},
{ "mData": 2 },
{ "mData": 3 },
{ "mData": 4 },
{ "mData": 5 }
]
});
} );
[/code]
If I understand correctly all I need to do is to implement the following:
[code]
$.fn.dataTableExt.oApi.fnVisibleToColumnIndex = function ( oSettings, iMatch )
{
return oSettings.oApi._fnVisibleToColumnIndex( oSettings, iMatch );
};
[/code]
I would appreciate any hint on where and how should I put it if it is the right direction at all.
This discussion has been closed.
Replies
Personally I'd recommend using objects rather than arrays, particularly if you are going to hide some data. It will make life much easier: http://datatables.net/release-datatables/examples/server_side/object_data.html
Allan
Thanks a lot.
I made the following change to the PHP example.
[code]
$sOrder .= "`".$aColumns[ intval( $_GET['iSortCol_'.$i]+1 ) ]."` ".
[/code]
Instead of
[code]
$sOrder .= "`".$aColumns[ intval( $_GET['iSortCol_'.$i]) ]."` ".
[/code]
Now it works great.