json - JQuery Datatables without Array -
i'm having problem populating table, accessing text file has json this:
{ "1000": { "country": "us", "eventid": 1000, "venue": "san francisco, usa" }, "2000": { "country": "de", "eventid": 2000, "venue": "munich, germany" }, "3000": { "country": "gb", "eventid": 3000, "venue": "uk (market house)" } }
i have followed examples on datatables.net , tried loading on html
<html> <head> <title>hello world</title> <link rel="stylesheet" type="text/css" href="bootstrap.min.css"/> <link rel="stylesheet" type="text/css" href="datatables.bootstrap.css"/> <script type="text/javascript" src="jquery-1.11.1.min.js"></script> <script type="text/javascript" src="jquery.datatables.min.js"></script> <script type="text/javascript" src="datatable.js"></script> <script type="text/javascript" src="datatables.bootstrap.js"></script> </head> <body> <table id="example" class="table table-striped table-bordered" cellspacing="0" width="100%"> <thead> <tr> <th>country</th> <th>event</th> <th>venue</th> </tr> </thead> </table> </body> </html>
and datatable.js simple this
$(document).ready(function() { $('#example').datatable( { "processing": true, "ajax": 'sample.txt', "columns": [ { "country" }, { "eventid" }, { "venue" } ] } ); } );
can help me figure out have gone wrong code ?
i managed prepare issue adding custom function part of datasrc attribute (thanks jongyu lin). here alter javascript
$(document).ready(function () { $('#example').datatable({ "processing": true, "ajax": { "url": 'json.txt', "datasrc": function (json) { var arr = object.keys(json).map(function(k) { homecoming json[k] }); homecoming arr; } }, "columndefs": [ { "targets": [2], "visible": true, "searchable": true } ], "columns": [ { "data": "eventid" }, { "data": "country" }, { "data": "venue" } ] }); });
json jquery-datatables
No comments:
Post a Comment