how to load the local JSON variable using jquery datatable

前端 未结 5 1149
醉话见心
醉话见心 2020-12-28 08:09

I have a local JSON dataset. I want to use jquery datatable plugin to display it. Is there any setting or configuration inside datatable plugin to display data? All I can fi

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-28 08:37

    Use data option to supply data for a table.

    For example:

    var table_data = [
        [ "Tiger Nixon", "System Architect", "$3,120", "2011/04/25", "Edinburgh", 5421 ],
        [ "Garrett Winters", "Director", "$8,422", "2011/07/25", "Edinburgh", 8422 ]
    ];
    
    $('#example').DataTable( {
        data: table_data
    } );
    

    If your data is a string in JSON format, you may want to parse it first with either $.parseJSON() or JSON.parse().

    See this jsFiddle for code and demonstration.

提交回复
热议问题