【问题标题】:Ajax sorting server-side, is iSortCol_0 considering hiddend columns?Ajax 排序服务器端,iSortCol_0 是否考虑隐藏列?
【发布时间】:2012-02-27 15:10:37
【问题描述】:

我不知道这是否是一个错误,但我有一个带有以下选项的数据表+ajax:

     "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" }
                ]

我有一个表单,用户可以在其中添加行,当他们提交它时,我使用 ajax 调用将数据添加到数据库中,然后调用: jQuery('#mydatatable').dataTable().fnReloadAjax();

当用户单击以按列“MainTag”对表格进行排序时,我的服务器端 ajax 接收到:

iSortCol_0 4
iSortingCols 1

所有 bSortable_# 都在那里,正确地从 0 到 7(我有 8 列,如上所示。

现在我的问题是 iSortCol_0 具有误导性,因为隐藏的列,如果我不知道服务器上隐藏了哪些列,我会误解 iSortCol_0=4 按错误的列排序。

我可以实施一种解决方法,将在外部显示或隐藏哪些列的信息发送到数据表,但我觉得要么我做错了,要么我错过了在文档中找到我的问题的答案。

【问题讨论】:

    标签: javascript ajax jquery-datatables


    【解决方案1】:

    我不认为有一种自动的方法可以知道这一点,我要做的是使用fnServerParams()(如this 示例中所述)向服务器发送一个额外的参数,以告知服务器什么列被隐藏

        "fnServerParams": function ( aoData ) {
            aoData.push( { "name": "more_data", "value": "my_value" } );
        }
    

    【讨论】:

    • 谢谢/感恩。看起来是一个合理的标准解决方案!
    猜你喜欢
    • 2018-06-24
    • 1970-01-01
    • 1970-01-01
    • 2010-09-22
    • 2020-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-01
    相关资源
    最近更新 更多