繁体   English   中英

如何在jQuery DataTables中添加静态列

[英]How to add static column(s) in jQuery DataTables

我正在使用jQuery DataTables 1.10.7。 我列了几列。 因为少数列是静态的,很少是动态的。

所以目前我在DataTable中绑定了大约20列(静态+动态)。 现在,我已经绑定到20列,现在假设如果我绑定21列,那就给我错误了

DataTables警告:table id = DataGrid - 无效的JSON响应。 有关此错误的更多信息,请参阅http://datatables.net/tn/1

请附上截图。 在第一个快照中,它一直工作到手头列,下一个屏幕截图将显示错误,而我正在绑定OnHand的下一列。

我在DataTable中也设置了这个部分。

"aoColumns": [
   { sWidth: '1%' }, { sWidth: '5%' }, { sWidth: '5%' }, { sWidth: '5%' }, { sWidth: '5%' }, { sWidth: '5%' },
   { sWidth: '5%' }, { sWidth: '5%' }, { sWidth: '5%' }, { sWidth: '5%' }, { sWidth: '5%' }, { sWidth: '5%' },
   { sWidth: '5%' }, { sWidth: '5%' }, { sWidth: '5%' }, { sWidth: '5%' }, { sWidth: '5%' }, { sWidth: '5%' },
   { sWidth: '5%' }, { sWidth: '5%' }, { sWidth: '5%' }, { sWidth: '5%' }
 ],

在此输入图像描述在此输入图像描述

我的代码在这里

function OnddlRegionRankGroupChange(val) {

  var Tblheader = '';
  var trHTML = '';

  Re_Bind_DataTable();
  $("#DataGrid").empty()

  Tblheader = '<thead><tr><th rowspan="2" style="width: 5%;">Excl.</th><th rowspan="2">CUC</th> <th rowspan="2"> Late Model </th><th colspan="2">' + '1 Year Rank </th><th colspan="2"> 1 Year Sales Qty </th> <th rowspan="2"> Whse Looksup </th><th colspan="12" align="center"> Qty of Parts Sold by Mo.' +
     '</th> <th rowspan="2"> Days OOS </th> <th rowspan="2"> On Hand </th> <th colspan="4" align="center"> Re-Order High </th> <%--<th> &nbsp; </th>--%> ' +
     '</tr> <tr> <th> Whse </th> <th> Region </th><th> Whse </th> <th>Region</th><th> 12 </th> <th>11</th> <%--<th> .... </th>--%> <th class="cellhidden"> ' +
     '10 </th> <th class="cellhidden">9 </th> <th class="cellhidden"> 8 </th> <th class="cellhidden"> 7  </th> <th class="cellhidden"> 6 </th>' +
     '<th class="cellhidden"> 5 </th>  <th class="cellhidden">4 </th> <th> 3</th>  <th>2 </th> <th> 1  </th> <th> Current </th> <th> Diff </th> <th>' +
     ' Recomd </th> <th> Last </th> <%--<th>  &nbsp; </th>--%>   </tr> </thead>';

  $("#DataGrid").append(Tblheader);

  $('#DataGrid').DataTable({
     "iDisplayLength": 25,
     "aaSorting": [[0, 'desc']],
     "bServerSide": true,
     "bProcessing": false,
     "bPaginate": true,
     "sDom": 'fltip',
     "bDeferRender": true,
     "sAjaxSource": '<%= Url.Action("GetTest") %>',
     "fnServerParams": function (aoData) {
        aoData.push({ "name": "WhseID", "value": $("#ddlWarehouse").val() },
                    { "name": "strCatg", "value": $("#ddlCategory").val() })
     },
     "aoColumns": [
        { sWidth: '1%' }, { sWidth: '5%' }, { sWidth: '5%' }, { sWidth: '5%' }, { sWidth: '5%' }, { sWidth: '5%' },
        { sWidth: '5%' }, { sWidth: '5%' }, { sWidth: '5%' }, { sWidth: '5%' }, { sWidth: '5%' }, { sWidth: '5%' },
        { sWidth: '5%' }, { sWidth: '5%' }, { sWidth: '5%' }, { sWidth: '5%' }, { sWidth: '5%' }, { sWidth: '5%' },
        { sWidth: '5%' }, { sWidth: '5%' }, { sWidth: '5%' }, { sWidth: '5%' }
     ],      
     "fnInitComplete": function (oSettings, json) {
        setTimeout(function () { $.loader('close'); }, 1000);
     }
  });
}

最后我得到了回答我的问题。 实际上,我的问题是我已经绑定到20列(包括静态和动态)。 直到20列,它运作良好。 但是一旦我继续尝试在那个时候增加一个col(21th cols),我就面临着问题。

解决方案是只需在DataTable配置设置中设置以下行

“sServerMethod”:“POST”,

例如

 $("#DataGrid").DataTable({
                        "iDisplayLength": 10,
                        "bServerSide": true,
                        "sDom": 'fltip',
                        "sAjaxSource": '<%= Url.Action("GetTest") %>',
                        *"sServerMethod": "POST"*
})

因为Post Method存储响应能力优于GET Response。 获取具有存储响应限制的方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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