DataTables warning (table id = 'myTable'): Requested unknown parameter '0' from the data source for row 0

摘要:
第一种方式:不用在js里设置列Html:Title-1Title-2Title-3Title-4Title-5Title-6Title-7Title-8Title-9Ti

第一种方式:不用在js里设置列
Html:

<table id="myTable">
        <thead>
            <tr>
                <th>Title-1</th>
                <th>Title-2</th>
                <th>Title-3</th>
                <th>Title-4</th>
                <th>Title-5</th>
                <th>Title-6</th>
                <th>Title-7</th>
                <th>Title-8</th>
                <th>Title-9</th>
                <th>Title-10</th>
                <th>Title-11</th>
                <th>Title-12</th>......
            </tr>
        </thead>
        <tbody></tbody>
 </table>

Javascript:

<script type="text/javascript">$(function() {
        $('#myTable').dataTable({
            "bServerSide": true,
            "sAjaxSource": "/Home/TodaySO",
            "bPaginage": true,
            "sPaginationType": "full_numbers",
            "iDisplayLength": 5,
            "oLanguage": { "sUrl": "/Scripts/DataTable/dataTable_cn.txt"}//多语言配置
//注意这里没有配置列的信息!
});//end table });//end ready() </script>

Controller:

var result = from f in filteredData.OrderBy(o =>o.SalesOrder)
                .Skip(param.iDisplayStart)
                .Take(param.iDisplayLength)
                .ToList()
            select new[]{
                        f.Field-1,
                        f.Field-2,        
                        f.Field-3,        
                        f.Field-4,        
                        f.Field-5,        
                        f.Field-6,        
                        f.Field-7,        
                        f.Field-8,        
                        f.Field-9,        
                        f.Field-10,        
                        f.Field-11,        
                        f.Field-12
...... };

---------------FireBug------------

数组格式:

{"sEcho":"1","iTotalRecords":2210,"iTotalDisplayRecords":2210,
    "aaData":[
        ["3004582952","10  "],
        ["3004582952","100 "],
        ["3004582952","20  "],
        ["3004582952","30  "],
        ["3004582952","40  "]
    ]
}

第二种方式:要在js里设置列
Html:

 <table id="myTable">
    <thead>
       <tr>
            <th>Title-1</th>
            <th>Title-2</th>
            <th>Title-3</th>
            <th>Title-4</th>
            <th>Title-5</th>
            <th>Title-6</th>
            <th>Title-7</th>
            <th>Title-8</th>
            <th>Title-9</th>
            <th>Title-10</th>
            <th>Title-11</th>
            <th>Title-12</th>......
        </tr>
    </thead>
    <tbody></tbody>
</table>

Javascript:

<script type="text/javascript">$(function() {
        $('#myTable').dataTable({
            "bServerSide": true,
            "sAjaxSource": "/Home/TodaySO",
            "bPaginage": true,
            "sPaginationType": "full_numbers",
            "iDisplayLength": 5,
            "oLanguage": { "sUrl": "/Scripts/DataTable/dataTable_cn.txt" },//多语言配置
            "aoColumns": [
                { "mData": "Field-1"},
                { "mData": "Field-2"},
                { "mData": "Field-3"},
                { "mData": "Field-4"} ,
                { "mData": "Field-5"} ,
                { "mData": "Field-6"} ,
                { "mData": "Field-7"} ,
                { "mData": "Field-8"} ,
                { "mData": "Field-9"} ,
                { "mData": "Field-10"} ,
                { "mData": "Field-11"} ,
                { "mData": "Field-12"} 
                ......
            ]
        });//end table
    });//end ready()
</script>

Controller:

 var result = from f infilteredData
                  .OrderBy(o =>o.SalesOrder)
                  .Skip(param.iDisplayStart)
                  .Take(param.iDisplayLength)
               select f;

---------------FireBug------------

Javascript对象格式:

{
    "sEcho":"1",
    "iTotalRecords":2210,
    "iTotalDisplayRecords":2210,
    "aaData":[
        {"SalesOrder":"3004582952","SalesOrderItem":"10  ","CustomerPO":"SEG131800",...},
        {"SalesOrder":"3004582952","SalesOrderItem":"100 ","CustomerPO":"SEG131801",...},
        {"SalesOrder":"3004582952","SalesOrderItem":"20  ","CustomerPO":"SEG131802",...},
        {"SalesOrder":"3004582952","SalesOrderItem":"30  ","CustomerPO":"SEG131803",...},
        {"SalesOrder":"3004582952","SalesOrderItem":"40  ","CustomerPO":"SEG131804",...}
    ]
}

免责声明:文章转载自《DataTables warning (table id = 'myTable'): Requested unknown parameter '0' from the data source for row 0》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇p标签多行文字内容实现上下垂直居中兼容ie8ER图向关系模型的转换遵循原则(转载)下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

DataTable某一列的最大值

1.datatable.compute("max(列名)","")eg:  int max_Idx_Number = 1;     int.TryParse(Convert.ToString(dtGvModel.Compute("max(" + POR_WORK_ORDER_REC_FIELDS.FIELD_IDX_NUMBER + ")", "")),...

关于值类型与列类型不匹配,所需类型是 DataRow"的解决方案

今天,在vs2005下将SqlDataReader 转换为DataTable时,出现了 "值类型与列类型不匹配不能在 ID 列中存储 <30>。所需类型是 DataRow"的错误码,后来查了后,原来是这里的问题,查找相关资料后发现,(把蓝字部分修改成红字部分),修改成功 public static DataTable ConvertDataR...

datatable 参数详解

datatable 详解 var docrTable = $('#docrevisontable').dataTable({ language:lang, //提示信息 autoWidth: false, //禁用自动调整列宽 stripeClasses: ["odd", "even"], //为奇偶行加上样式,兼容不支持CSS伪类的场合...

NPOI导出EXCEL数据量大,分多个sheet显示数据

//NPOIHelper  类关键代码 using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Data;using System.IO;using NPOI.HSSF.UserModel;using System.Coll...

DataTable合并列

datatable合并两个列     DataSet ds = bll.GetList("CompanyID=" + CompanyID);            DataTable dt = ds.Tables[0];            dt.Columns.Add("Text", System.Type.GetType("System.Objec...

将List&amp;lt;T&amp;gt;转化成 DataTable调整可空类型的转化错误

加载表结构并保持成XML View Code string cmdText = @"select * from kb_lable_temp where 1=2"; using (SqlConnection conn = new SqlConnection(DBCtx.ConnStr))...