DataTables:为第14行添加新行请求的未知参数“id”

时间:2017-06-18 15:50:47

标签: javascript jquery datatable

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的行。

那么解决方案是什么?

1 个答案:

答案 0 :(得分:0)

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 = '';

            });
        }

在这里,我自己的代码可能会帮助你