C# 如何在jQuery数据表中添加静态列

C# 如何在jQuery数据表中添加静态列,c#,jquery,asp.net-mvc,datatables,C#,Jquery,Asp.net Mvc,Datatables,我使用的是jQuery DataTables 1.10.7。我装订了几列。在这种情况下,很少有列是静态的,也很少有列是动态的 所以目前我在DataTable中绑定了大约20列(静态+动态)。现在,我已经绑定到20列,现在假设我绑定21列,它会给我类似的错误 DataTables警告:表id=DataGrid-JSON响应无效。有关此错误的详细信息,请参阅 请附上截图。在第一个快照中,它一直工作到手头上的列,当我绑定手头上的下一列时,下一个屏幕截图将显示错误 我也在我的数据表中设置了这个部分 "a

我使用的是jQuery DataTables 1.10.7。我装订了几列。在这种情况下,很少有列是静态的,也很少有列是动态的

所以目前我在DataTable中绑定了大约20列(静态+动态)。现在,我已经绑定到20列,现在假设我绑定21列,它会给我类似的错误

DataTables警告:表id=DataGrid-JSON响应无效。有关此错误的详细信息,请参阅

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

我也在我的数据表中设置了这个部分

"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);
     }
  });
}
函数OnddlRegionRankGroupChange(val){
var Tblheader='';
var trHTML='';
重新绑定数据表();
$(“#数据网格”).empty()
Tblheader=‘不包括CUC最新型号’+‘1年排名1年销售数量,为什么按生产订单销售的零件数量’+
“现有OOS天数重新订购高”+
“Whse地区Whse地区12 11”+
'10  9   8   7    6 ' +
“5 4 3 2 1电流差”+
“最后推荐”;
$(“#数据网格”).append(Tblheader);
$('#DataGrid')。数据表({
“iDisplayLength”:25,
“aaSorting”:[[0,'说明']],
“bServerSide”:正确,
“b处理”:false,
“bPaginate”:对,
“sDom”:“fltip”,
“bDeferRender”:没错,
“sAjaxSource”:“”,
“fnServerParams”:函数(aoData){
aoData.push({“name”:“WhseID”,“value”:$(“#ddlWarehouse”).val()},
{“name”:“strCatg”,“value”:$(“#ddlcontegory”).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%}
],      
“fnInitComplete”:函数(oSettings,json){
setTimeout(函数(){$.loader('close');},1000);
}
});
}

我终于得到了问题的答案。 实际上,我的问题是我必须绑定到20列(包括静态和动态)。直到20科尔,它一直运作得很好。但当我继续尝试添加一个列(第21列)时,我就面临着这个问题

解决方案是 只需在DataTable配置设置中的下一行进行设置

“sServerMethod”:“POST”,

e、 g

$(“#数据网格”).DataTable({
“iDisplayLength”:10,
“bServerSide”:正确,
“sDom”:“fltip”,
“sAjaxSource”:“”,
*“sServerMethod”:“POST”*
})

因为Post方法存储响应的容量比GET响应好。获取具有存储响应限制的方法。

我们需要您提供更多信息。这个错误是由您的ajax调用触发的吗?请告诉我们您是如何将数据绑定到数据表的显示您是如何添加动态列的以及您是如何初始化数据表的?是的,我已经更新了我的问题。现在您可以检查了。请按照错误表中链接的建议发布您的JSON响应,这将清楚显示“无效JSON响应”的原因。
 $("#DataGrid").DataTable({
                        "iDisplayLength": 10,
                        "bServerSide": true,
                        "sDom": 'fltip',
                        "sAjaxSource": '<%= Url.Action("GetTest") %>',
                        *"sServerMethod": "POST"*
})