How can I use a local JSON object as a data source for jQuery DataTables

后端 未结 2 1489
我寻月下人不归
我寻月下人不归 2020-12-05 05:17

I have a local JSON object formatted like this:

[{
    \"id\": \"58\",
    \"country_code\": \"UK\",
    \"title\": \"Legal Director\",
    \"pubdate\": \"20         


        
相关标签:
2条回答
  • 2020-12-05 05:49

    The property to supply your own data is aaData NOT aoData:

    testdata = [{"id":"58",...}]; // local object
    
    $('#test').dataTable({
        "aaData": testdata,
        "aoColumns": [
            { "mDataProp": "id" },
            { "mDataProp": "country_code" },
            { "mDataProp": "title" },
            { "mDataProp": "pubdate" },
            { "mDataProp": "url" }
        ]
    });
    

    Working fiddle

    0 讨论(0)
  • 2020-12-05 05:53

    I encoutered the same problem, solution is like this: Place $('#list_table').dataTable code in setTimeout function to postpone dataTable application for 5 seconds:

    setTimeout("$('#list_table').dataTable ...." , 5000);
    

    I noticed that apply dataTable plugin in firebug after the table is loaded, it doesn't show error as "No data available in table".

    0 讨论(0)
提交回复
热议问题