weixin_33724570 2017-04-26 14:26 采纳率: 0%
浏览 202

DataTables Ajax不起作用

I have This table which i'm trying to add ajax by adding this code :

$('#example').DataTable({
    'serverSide': true,
    "bPaginate": false,
    "info": false,
    "iDisplayLength":20,
    "bLengthChange":false,
    'ajax': {
        type: 'GET',
        'url': 'https://api.myjson.com/bins/ftw5f',
        'data': function(data) {
            return data;
        }
    },
    "columns": [{
        "data": 'Name'
    }, {
        "data": 'Position'
    }, {
        "data": 'Office'
    },
        {
            "data": 'Age'
        },
        {
            "data": 'Start date'
        },
        {
            "data": 'Salary'
        },

    ],

    initComplete: function () { // the filters });

When it's hard coded - like in fiddle - it's working - but when i add the ajax - and remove all the hard coded tr's - the filters don't work.... i checked the console for errors - but there are none.... thanks.

  • 写回答

2条回答 默认 最新

  • H_MZ 2017-04-26 15:00
    关注

    Your columns declaration is incorrect, the right side should be the key whose value should appear in that column not a label for that column.

    If your data is like:

    {
      name: '',
      position: '',
      office: '',
      age: '',
      start_date: '',
      salary: '',
    }
    

    Then columns should look like:

    "columns": [{
        "data": 'name'
      }, {
        "data": 'position'
      }, {
        "data": 'office'
      }, {
        "data": 'age'
      }, {
        "data": 'start_date'
      }, {
        "data": 'salary'
      },
    ],
    

    See the docs for more info: https://datatables.net/manual/ajax#Column-data-points

    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮