It is necessary to transfer data from mysql to the page in the datatables plugin. Controller:

@RequestMapping(value = "/getData", method = RequestMethod.POST) public @ResponseBody List<Result> getData(){ return service.findAll(); } 

Page:

 <table id="resultTable" class="dataTable"> <thead> <tr> <th>ID</th> <th>Name</th> <th>Symbol</th> <th>Preis</th> <th>PJ</th> <th>EJT</th> <th>EJH</th> <th>T1</th> <th>T6</th> </tr> </thead> <tfoot> <tr> <th>ID</th> <th>Name</th> <th>Symbol</th> <th>Preis</th> <th>PJ</th> <th>EJT</th> <th>EJH</th> <th>T1</th> <th>T6</th> </tr> </tfoot> </table> <script> $.ajax({ url : "getData", dataType : "json", type: "POST", success : function(json) { alert("Success"); $('#resultTable').dataTable(json); }, error: function () { alert("Error"); } }); </script> 

Json seems to be accepted, but how do I process it for datatable?

  • Please expand your question! What do you mean by "process for datatable" which json format? - JVic

1 answer 1

I decided:

 <script> $(document).ready(function () { $.ajax({ url: "getData", dataType: "json", type: "POST", success: function (json) { $('#resultTable').DataTable({ data: json, columns: [ {data: "name"}, {data: "price"}, {data: "symbol"}, {data: "pj"}, {data: "ejt"}, {data: "ejh"}, {data: "t1"}, {data: "t6"} ] }); } }); });