ColReorder and server-side PHP

ColReorder and server-side PHP

ackzellackzell Posts: 7Questions: 0Answers: 0
edited April 2011 in Plug-ins
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!

Replies

  • allanallan Posts: 63,686Questions: 1Answers: 10,500 Site admin
    Not sure I 100% understand I'm afraid. You say:

    > 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
  • ackzellackzell Posts: 7Questions: 0Answers: 0
    Thank you for answering 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!!
  • allanallan Posts: 63,686Questions: 1Answers: 10,500 Site admin
    Ah okay - are you taking into account the reordering on the server-side? Like as shown in the server_processing_ordering.php demo code? You need to convert from the index sent to the name index otherwise I think you encounter this issue.

    Allan
  • ackzellackzell Posts: 7Questions: 0Answers: 0
    Thanks again for responding, I'll give it a look and I'll post back.
  • ackzellackzell Posts: 7Questions: 0Answers: 0
    It works like a charm!!

    it was a matter of sorting on the server-side >_<

    thank you very much for this, it is wonderful!
  • dlicorishdlicorish Posts: 7Questions: 0Answers: 0
    Hey Allan,
    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
  • allanallan Posts: 63,686Questions: 1Answers: 10,500 Site admin
    Hi 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
This discussion has been closed.