最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin3浏览0评论

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 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.

Share Improve this question edited Oct 6, 2013 at 17:30 madth3 7,34412 gold badges52 silver badges74 bronze badges asked Feb 27, 2012 at 15:10 Max FavilliMax Favilli 6,4693 gold badges43 silver badges64 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

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" } );
    }
发布评论

评论列表(0)

  1. 暂无评论