简体   繁体   中英

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.

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" } );
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM