Column Sorting Sorts Wrong Columns - Off By Two
Column Sorting Sorts Wrong Columns - Off By Two
scriderpsd
Posts: 6Questions: 0Answers: 0
I have a curious bug in my Datatables implementation and I think the best way to illustrate it is with a screenshot.
http://psdapps.psd1.org/security-new-two/img/Snap1.jpg'
As you can see, I have sorted on the Student ID column yet the data is sorted on the Last Name column. This "off by two" error occurs across the entire table (except in the last two columns where I get a JSON formatting error when I attempt to sort).
Since I have a lot of columns, I won't post all the code but I will post what I assume is relevant.
[code]
oTable = $('#example').dataTable( {
"sScrollX": "100%",
"bScrollCollapse": true,
"aLengthMenu": [[10, 15, 20], [10, 15, 20]],
"iDisplayLength": 15,
"oLanguage": {
"sSearch": "Search all columns:"
},
"bSortClasses": true,
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "server_processing_details_col_3.php",
"aoColumns": [
{ "bSearchable": false, "bVisible": false, "bSortable": false}, // id - not visible - just used for indexing on the edits
{ "sClass": "center", "bSortable": false, "bSearchable": false}, // photo icon
{ "sClass": "center", "bSortable": false, "bSearchable": false}, // details/print icon
{ "sClass": "center" }, // student_id
null, // first_name
null, // last_name
null, // Address
[/code]
I have tried using iDataSort but could not get it to do anything. Any help would be appreciated.
Thanks,
Scott
http://psdapps.psd1.org/security-new-two/img/Snap1.jpg'
As you can see, I have sorted on the Student ID column yet the data is sorted on the Last Name column. This "off by two" error occurs across the entire table (except in the last two columns where I get a JSON formatting error when I attempt to sort).
Since I have a lot of columns, I won't post all the code but I will post what I assume is relevant.
[code]
oTable = $('#example').dataTable( {
"sScrollX": "100%",
"bScrollCollapse": true,
"aLengthMenu": [[10, 15, 20], [10, 15, 20]],
"iDisplayLength": 15,
"oLanguage": {
"sSearch": "Search all columns:"
},
"bSortClasses": true,
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "server_processing_details_col_3.php",
"aoColumns": [
{ "bSearchable": false, "bVisible": false, "bSortable": false}, // id - not visible - just used for indexing on the edits
{ "sClass": "center", "bSortable": false, "bSearchable": false}, // photo icon
{ "sClass": "center", "bSortable": false, "bSearchable": false}, // details/print icon
{ "sClass": "center" }, // student_id
null, // first_name
null, // last_name
null, // Address
[/code]
I have tried using iDataSort but could not get it to do anything. Any help would be appreciated.
Thanks,
Scott
This discussion has been closed.
Replies
Allan
As an example I have this in my php file:
[code]
// id is hidden
$columns = array( 'id', 'col_1', 'col_2', 'col_3' );
$c = count($columns);
for ($i = 0; $i < $c; $i++)
{
$s = $_GET[ 'sSearch_'.$i];
if ( ! empty($s))
{
// Add to where clause
}
$o_col = $_GET['iSortCol_'.$i];
if ( ! empty($o_col))
{
$o = $_GET['sSortDir_'.$i];
if ( ! empty($o))
{
// Add to order by statement
}
}
}
[/code]
The code is slightly abridged as it was kinda Kohana ORM specific, but the theory is good (unless Allan says otherwise ;P)
Chris
Scott