how to load the local JSON variable using jquery datatable

前端 未结 5 1171
醉话见心
醉话见心 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:45

    Solving the problem with the jessegavin answer:

    $(document).ready(function (){
    
    var json = {
      BrowserStats : [
        { engine: "Trident", browser: "IE 4.0", platform: "Win 95+", version: 4 },
        { engine: "Trident", browser: "IE 5.0", platform: "Win 95+", version: 5 },
        { engine: "Trident", browser: "IE 5.5", platform: "Win 95+", version: 5.5 }
      ]
    };
    
    var data = jQuery.map(json.BrowserStats, function(el, i) {
      return [[el.engine, el.browser, el.platform, el.version]];
    });
    
    $('#example').dataTable( {
      "aaData": data,
      "aoColumns": [
        { "sTitle": "Engine" },
        { "sTitle": "Browser" },
        { "sTitle": "Platform" },
        { "sTitle": "Version"}
      ]
     });
    });
    

    https://jsfiddle.net/byejn8ye/

提交回复
热议问题