weixin_33725272 2016-06-20 18:59 采纳率: 0%
浏览 23

限制数据表字段

I am using AJAX to source my datatables data. However, I am getting the error:

unknown parameter '0' for row 0, column 0

because my ajax response object has more fields than what I defined in my table's initialization. Is there a way I can limit or specify what parts of the ajax response go into my datatable? Here's my javascript:

$.ajax({
    type: "GET",
    url: "/api/admin/employees",
    success: function(data) {
        $('#eployees').DataTable({
                responsive: true,
                data: data,
                columns: [
                    { title: "Name" },
                    { title: "Position" },
                    { title: "Office" },
                    { title: "Extn." },
                    { title: "Start date" },
                    { title: "Salary" }
                ]
        });
    },
    error: function(data, status, res) {
        console.log('error...');
        console.log(res);
    }
});

Note - my data object contains 20 fields, but I only need the 6 that are defined below.

Can someone help? Thanks in advance!

  • 写回答

1条回答 默认 最新

  • 三生石@ 2016-06-21 01:37
    关注

    Your records (data) should be JSON, not array (see example https://datatables.net/reference/option/columns.data#Examples) The examples show how to create mapping column to data field

    评论

    报告相同问题?

    悬赏问题

    • ¥15 B660主板安装xp系统老是出现错误怎么办
    • ¥15 定义过的变量报错未定义
    • ¥15 如何在EXCEL某单元格中查找是否存在另一列中的内容。
    • ¥50 非对称加密(相关搜索:密码学)
    • ¥15 关于非编程寻迹小车的分析
    • ¥15 java导出EXCEL这里已经执行成功了,但是流浪器没有下载
    • ¥15 帮我把代码改的能正常运行就行
    • ¥50 有限元修正、模型修正、最小二乘法,详细步骤
    • ¥15 用plc编写梯形程序
    • ¥15 关于#物联网#的问题:新大陆AIOT中,按照手册教程进行添加,设置完成后网关一直不上线,显示Never这是网络服务的信息