简体   繁体   中英

Data not getting populated in JQuery Datatable

I am making an Ajax call and the returned value is stored in "data" variable. Now, I want to use this "data" (in the form of JSON object) to bind the table 'templateRegArea'.

$.ajax({
    url: "Ajax_UserPermissionProfile.aspx/GetTemplatePropertyList",
    method: 'post',
    type: "POST",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    data: "{ 'iAcctId': '" + $('#hidIAcctId').val() + "', 'iTemplateID': '" + templateID + "'}",

    success: function(response) {
        var data = eval((response.d != undefined) ? response.d : response);
        alert(data);
        $('#templateRegArea').DataTable({
            ajax: data,
            columns: [{
                data: data.ID
            }, {
                data: data.Name
            }, {
                data: null,
                className: "center",
                defaultContent: '<a href="" class="editor_edit">Edit</a> / <a href="" class="editor_remove">Delete</a>'
            }]
        });
    },
    error: function(error) {}
}

I am getting the following error.

错误

在此处输入图片说明

有时,数据表希望所有列都与JSON中发送的数据进行映射。

I assume these "ID" and "Name" values are the values you want to put on your table as rows. The "columns" DataTable property expects to get the names of the columns, not its values. From the documentation example :

$('#example').DataTable({
    "columns": [
        { "data": "name" },
        { "data": "position" },
        { "data": "office" },
        { "data": "age" },
        { "data": "start_date" },
        { "data": "salary" }
    ]
});

What you should do is create the columns with "data": "ID" and "data: Name" and then add those values as rows.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM