【问题标题】:DataTables: Adding new row Requested unknown parameter 'id' for row 14DataTables:为第 14 行添加新行请求的未知参数“id”
【发布时间】:2017-06-18 15:50:47
【问题描述】:

AJAX

{
    "data": [
        {
            "id": 1,
            "name": "Dashboard",
            "url": "/",
            "icon": "icon-home",
            "child_of": null,
            "show": 1,
            "admin": 0
        },
        {
            "id": 2,
            "name": "Submenu 3",
            "url": "http://stackoverflow.com",
            "icon": null,
            "child_of": null,
            "show": 1,
            "admin": 0
        },
    ]
}

JS

$('#table-editable').dataTable({
    "ajax": {
        "url": "/api/menu",
        "type": "GET",
    },
        "columns": [
            { "data": "id" },
            { "data": "name" },
            { "data": "url" },
            { "data": "icon" },
            { "data": "child_of" },
            { "data": "show" },
            { "data": "admin" }
        ]
});

所以我使用 AJAX 来填充表格中的数据。它正在工作。

我正在使用这个:DataTables: Inline Editing 来创建新行。 (在链接中检查添加行和编辑模式

问题:

假设我有 13 行。所以 ID 将是 1、2、3... 13。

创建新行时: 它这样做:oTable.fnAddData('', '',....); 所以当我添加新行时,它给了我错误:

DataTables 警告:table id=table-editable - 请求第 14 行的未知参数“id”。有关此错误的详细信息,请参阅 datatables.net/tn/4

所以,基本上它会尝试获取 id 14 的行。但是,没有 id 为 14 的行。

那么解决办法是什么?

【问题讨论】:

    标签: javascript jquery datatable


    【解决方案1】:
    var data = [
        {
            "CategoryID": 1,
            "CategoryName": "Soler Power Plant",
            "CategoryProducts": [
            {
                "ID": 1,
                "Name": 'Commercial Solar Power Plant',
                "SubTitle": 'Eco, Eco Friendly, Energy, Green, Solar',
                "Brand": 'ACS',
                "Usage": '',
                "Type": '',
                "Price": 'Rs 5 Lakh / Unit',
                "Body_Material": '',
                "Description": 'Having a pre-determined quality administration system, we are thoroughly involved in delivering Commercial Solar Power Plant.',
                "ImageUrl": 'assets/images/Products/Sola-power-plant.jpg',
            },
            {
                "ID": 2,
                "Name": 'Industrial Solar Power Plants',
                "SubTitle": 'Eco Friendly, Save Energy',
                "Brand": 'ACS',
                "Usage": '',
                "Type": '',
                "Price": 'Rs 5 Lakh / Unit',
                "Body_Material": '',
                "Description": 'So as to become a preferential business name, we are thoroughly engrossed in shipping an inclusive collection of Industrial Solar Power Plants.',
                "ImageUrl": 'assets/images/Products/Industrial_Solar_Power_Plants.jpg',
            },
             {
                 "ID": 3,
                 "Name": 'On Grid Solar Plant',
                 "SubTitle": 'Eco Friendly, Save Energy',
                 "Brand": 'ACS',
                 "Usage": '',
                 "Type": '',
                 "Price": 'Rs 1.1 Lakh / Unit',
                 "Body_Material": '',
                 "Description": "We are the leading firm of On Grid Solar Plant. To sustain the quality, our products are made under the guidance of industry certified professionals.",
                 "ImageUrl": 'assets/images/Products/On_Grid_Solar_Plant.jpg',
             },
              {
                  "ID": 4,
                  "Name": 'On Grid Solar Power Plant',
                  "SubTitle": 'Eco Friendly, Save Energy',
                  "Brand": 'ACS',
                  "Usage": '',
                  "Type": '',
                  "Price": 'Rs 5 Lakh / Unit',
                  "Body_Material": '',
                  "Description": "We are the leading firm of On Grid Solar Power Plant. To sustain the quality, our products are made under the guidance of industry top professionals.",
                  "ImageUrl": 'assets/images/Products/On_Grid_Solar_Power_Plant.jpg',
              },
              {
                  "ID": 5,
                  "Name": 'Solar Power Plant',
                  "SubTitle": 'Eco Friendly, Save Energy',
                  "Brand": 'ACS',
                  "Usage": '',
                  "Type": '',
                  "Price": 'Rs 5 Lakh / Unit',
                  "Body_Material": '',
                  "Description": "We are the leading firm of Solar Power Plant. To sustain the quality, our products are made under the guidance of industry certified professionals.",
                  "ImageUrl": 'assets/images/Products/Solar_Power_Plant.jpg',
              },
            ]
        }
    ]
    
    
    
    
     function GetProducts() {
    
                var products = data;
    
                $.each(products, function () {
    
                    //var product = products.filter(filterByID)
                    var product = this;
                    $('#ProductDetails').append('<h2 class="text-center">' + this.CategoryName + '</h2>');
                    var details = product;
                    $.each(details.CategoryProducts, function () {
    
    
                        tempData = tempData + '<div class="col-md-4 col-sm-6">' +
                                        '<div class="project-box">' +
                                            '<div class="frame-outer">' +
                                                '<div class="frame">' +
                                                    '<img style="width:350px;" src="' + this.ImageUrl + '" class="attachment-340x220 size-340x220 wp-post-image" alt="">' +
                                                '</div>' +
                                            '</div>' +
                                            '<div class="text-box">' +
                                                '<h3><a>' + this.Name + '</a></h3>' +
                                                '<div class="tags-row">' +
                                                    '<a class="link">' + this.SubTitle + '</a>' +
                                                '</div>' +
                                                '<p>' + this.Description + '</p>' +
                                                //'<a href="javascript:ViewMore(' + this.ID + ')" class="btn-readmore">More Details</a>' +
                                            '</div>' +
                                        '</div>' +
                                    '</div>';
                    });
    
                    $('#ProductDetails').append('<div class="row">' + tempData + '</div>');
                    tempData = '';
    
                });
            }
    

    这是我自己的代码,可能对你有帮助

    【讨论】:

    • 如果您的数据是静态的,那么您可以使用它。
    猜你喜欢
    • 2020-11-30
    • 2014-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多