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

    评论

报告相同问题?

悬赏问题

  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败