Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ajax sorting server-side, is iSortCol_0 considering hiddend columns?

I don't know if it's a bug, but I have a datatable+ajax with the following options:

     "bServerSide": true,
     "sAjaxSource": url,
     "fnServerData": function (sSource, aoData, fnCallback) {
        jQuery.ajax({
           "dataType": 'json',
           "type": "POST",
           "url": sSource,
           "data": aoData,
           "success": fnCallback
        });
     },
     "sPaginationType": "bootstrap",
     "aoColumns": [
                    { "sName": "Id", "sType": 'numeric', "bVisible": false },
                    { "sName": "PostingDate", "sType": 'Date' },
                    { "sName": "Userid", "sType": 'string', "bVisible": false },
                    { "sName": "DisplayName" },
                    { "sName": "Description" },
                    { "sName": "MainTag" },
                    { "sName": "Tags" },
                    { "sName": "HowMuch" }
                ]

I have a form where users can add rows and when they submit it I add data to the database with an ajax call and then call: jQuery('#mydatatable').dataTable().fnReloadAjax();

When a user click to sort the table by column "MainTag" my server-side ajax receives:

iSortCol_0 4
iSortingCols 1

And all bSortable_# are there, correctly from 0 to 7 (I have 8 columns as shown above.

Now my problem is iSortCol_0 is misleading, since the columns where hidden, if I don't have a mean to know which columns are hidden on the server I misinterpret iSortCol_0=4 sorting by the wrong column.

I can implement a workaround, sending the information of which columns are displayed or hidden externally to datatables but I have the feeling either I am doing something wrong or I have missed to find the answer to my problem in the documentation.

like image 719
Max Favilli Avatar asked Oct 08 '22 13:10

Max Favilli


1 Answers

I don't think that there is an automatic way to know that, what i'd do is send an extra parameter to the server using fnServerParams() (as detailed in this example) to inform the server about what columns are hidden

    "fnServerParams": function ( aoData ) {
        aoData.push( { "name": "more_data", "value": "my_value" } );
    }
like image 112
Nicola Peluchetti Avatar answered Oct 12 '22 11:10

Nicola Peluchetti