ColReorder and server-side PHP
ColReorder and server-side PHP
Hi, excellent work on this project, I am very excited about it. :)
There is just one thing I haven't figured out so far.
I'm trying to implement the ColReorder extra to a table I feed through a PHP V4 script.
I have added the $sColumns variable to the PHP script and also I added it to the $sOutput to generate the JSON data.
On my initialisation I have declared the 'sName' attribute for each column that matches the $sColumns variable data.
I am also using a jQuery UI theme.
The problem is that the data gets sorted by the column "number" I click in instead of the actual column.
Let me try to explain it better.
I have a certain arrangement of columns like this:
Col1 | Col2 | Col3
Then I drag the header of Col3 and make the table look like this:
Col3 | Col2 | Col1
When I click on Col3 header, data is sorted correctly on Col1.
Everything is "in it's right column" it is just sorted on the column that originally was there I guess.
I'm sorry I cant post any link, but if it is required, I'll try to reproduce this and upload it.
Thank you in advance and congratulations for the project!
There is just one thing I haven't figured out so far.
I'm trying to implement the ColReorder extra to a table I feed through a PHP V4 script.
I have added the $sColumns variable to the PHP script and also I added it to the $sOutput to generate the JSON data.
On my initialisation I have declared the 'sName' attribute for each column that matches the $sColumns variable data.
I am also using a jQuery UI theme.
The problem is that the data gets sorted by the column "number" I click in instead of the actual column.
Let me try to explain it better.
I have a certain arrangement of columns like this:
Col1 | Col2 | Col3
Then I drag the header of Col3 and make the table look like this:
Col3 | Col2 | Col1
When I click on Col3 header, data is sorted correctly on Col1.
Everything is "in it's right column" it is just sorted on the column that originally was there I guess.
I'm sorry I cant post any link, but if it is required, I'll try to reproduce this and upload it.
Thank you in advance and congratulations for the project!
This discussion has been closed.
Replies
> Then I drag the header of Col3 and make the table look like this:
> Col3 | Col2 | Col1
> When I click on Col3 header, data is sorted correctly on Col1.
But I would have expected if you click on Col3, regardless of it's position, then Col3 is the one which will be sorted. This is shown in the ColReorder server-side example: http://datatables.net/release-datatables/extras/ColReorder/server_side.html
Allan
That is precisely what I thought it was going to happen, but it is not. I based my implementation on code from that page, but It does not seem to work.
The column that is sorted is the one that was originally on the position I'm clicking.
this is what I have as initialisation :
[code]
oTable = $('#data_tables').dataTable( {
"fnDrawCallback": function(){
$('#data_tables tr').hover(
function()
{
$(this).children('td').each(function ()
{
if($(this).hasClass('sorting_1'))
$(this).addClass('higlightSort');
else
$(this).addClass('higlight');
});
},
function()
{
$(this).children('td').removeClass('higlight');
$(this).children('td').removeClass('higlightSort');
}
);
},
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "usuariosDataTables.php",
"oLanguage":
{
"sUrl": "spanish.txt"
},
"sDom": 'R<"H"lfr>t<"F"ip<',
"aoColumns": [
{ "sName": "users.payrollNumber" , "sWidth": "15%" },
{ "sName": "users.username" , "sWidth": "10%" },
{ "sName": "users.firstname" , "sWidth": "20%" },
{ "sName": "users.lastname" , "sWidth": "25%" },
{ "sName": "users.active" , "sWidth": "20px" },
{ "sName": "categorias.nombre" , "sWidth": "10%" },
{ "sName": "users.extension" , "sWidth": "10%" },
{ "sName": "roles.description" , "sWidth": "15%" }
],
"bStateSave": true
});
[/code]
it is based on code I've been founding here in the website.
thanks in advance!!
Allan
it was a matter of sorting on the server-side >_<
thank you very much for this, it is wonderful!
The server-side example for ColReorder appears broken. It's looking for "../../examples/examples_support/server_processing_ordering.php" as sAjaxSource, but it looks like that's been moved, perhaps to "..\..\examples\server_side\scripts\ordering.php"?
David
Yup - very good point! Thanks for that. I've just updated both ColReorder and DataTables for a little bit more than just the path changed - what I would tend to recommend with ColReorder now is to use mDataProp if you are using server-side processing. This effectively makes the ordering of the return information irrelevant since it's an object and not an array - making life that little bit easier. There still needs to be some knowledge sent to the server for what order the table columns are in, and that is now sent as mDataProp_{i} which will be introduced in DataTables 1.8.1 (to be released soon!), but overall a bit similar and a bit quicker.
Its all checked in on github if you want to grab it immediately, or I'll be doing some releases later on.
Regards,
Allan