数据表错误:“请求未知参数” [英] DataTables Error : “Requested unknown parameter”

查看:667
本文介绍了数据表错误:“请求未知参数”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  VAR标题= [{mDataProp:代理},{mDataProp:买方},{mDataProp:日期}];
$(文件)。就绪(函数(){
    $('#数据表)。dataTable的({
        bFilter:假的,
        bLengthChange:假的,
        iDisplayLength:25,
        bJQueryUI:真实,
        bServerSide:真实,
        bProcessing:真实,
        sPaginationType:full_numbers,
        aoColumns:头,
        sAjaxSource:'/报告/ TestPaging',
    });
});

如果我从我的$ C $删除aoColumns c中的数据表正常产生,但是当我添加aoColumns我得到:

数据表警告(表ID =数据表):请求从0行的数据源未知参数代理

HTML

 <表ID =数据表>
                <&THEAD GT;
                    &所述; TR>
                        <第i TMP< /第i
                        <第i TMP< /第i
                        <第i TMP< /第i
                    < / TR>
                < / THEAD>                <&TBODY GT;
                < / TBODY>
            < /表>

如何配置头名?我需要他们对我的排序。
难道他们必须相同,如日的标签?
从我的控制器JSON响应是确定的,因为它呈现很好,当我删除aoColumns

我的String [] [](VAR数据),每行3串并返回为

  JSON(新{
            sEcho = param.sEcho,
            iTotalRecords = visitRepository.Query.Count(),
            iTotalDisplayRecords = visitRepository.Query.Count(),
            aaData =数据
        },JsonRequestBehavior.AllowGet);


解决方案

在遇到由JSON和你的 aoColumns 定义的内容之间的不匹配导致错误。您在 aoColumns 目标必须究竟的相同的JSON,并在名称的JSON 必须的等于列在原来的HTML表的数量。请参阅文件澄清。你的情况,JSON的应该是这样的:

  [{
  代理:tM4Ga0zX
  买家:ZKwMEiIa
  日期:K3lS2yn9
},
...]

...和你的JSON犯规遵循方案。如果你不使用 aoColumns ,然后将数据按索引插入,叫不上名字 - 这就是为什么它是为你工作离不开它。

您配置了 sTitle 属性标题名称(标题):

  aoColumns:
  {mDataProp:代理商,sTitle:代理商},
  {mDataProp:买方,sTitle:买方},
  {mDataProp:日期,sTitle:日期}
]

看到根据您的问题,这个展示 - > http://jsfiddle.net/kLR7G/

var headers = [{ "mDataProp": "Agents" },{ "mDataProp": "Buyer" },{ "mDataProp": "Date" }];
$(document).ready(function () {   
    $('#data-table').dataTable({
        "bFilter": false,
        "bLengthChange": false,
        "iDisplayLength": 25,
        "bJQueryUI": true,
        "bServerSide": true,
        "bProcessing": true,
        "sPaginationType": "full_numbers",
        "aoColumns": headers,
        "sAjaxSource": '/report/TestPaging',         
    });
});

If I remove the aoColumns from my code the datatable is generated normally, but when I add aoColumns I get :

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

HTML:

<table id="data-table">
                <thead>
                    <tr>                          
                        <th>tmp</th>
                        <th>tmp</th>
                        <th>tmp</th>
                    </tr>
                </thead>

                <tbody>
                </tbody>
            </table>

How can I configure header names? I need them for my sorting. Do they have to be same as in "th" tags? Json response from my controller is ok because it renders fine when I remove aoColumns

I have string[][](var data) with 3 strings in each line and return it as

  Json(new{
            sEcho = param.sEcho,
            iTotalRecords = visitRepository.Query.Count(),
            iTotalDisplayRecords = visitRepository.Query.Count(),
            aaData = data
        }, JsonRequestBehavior.AllowGet);

解决方案

The error you are experiencing is caused by a mismatch between the contents of the JSON and your aoColumns definition. The names you are targeting in aoColumns must be exactly the same as those in the JSON, and the length of each object in the JSON must be equal to the number of columns in the original HTML table. See the docs for clarification. In your case, the JSON should look like this :

[{
  "Agents": "tM4Ga0zX",
  "Buyer": "ZKwMEiIa",
  "Date": "K3lS2yn9"
},
...]

...And your JSON doesnt follow that scheme. If you are not using aoColumns, then the data is inserted by index, not by name - and that is why it is working for you without it.

You configure header names (titles) by the sTitle property :

aoColumns: [
  { mDataProp: "Agents", sTitle : "Agents" }, 
  { mDataProp: "Buyer", sTitle : "Buyer" },
  { mDataProp: "Date", sTitle : "Date" }
]

see this demonstration based on your question -> http://jsfiddle.net/kLR7G/

这篇关于数据表错误:“请求未知参数”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆