Topic: JSON to DataTable

sergeyzh free asked 6 years ago


Is there any chance to feed DataTable with JSON data without making AJAX requests (just need to add JSON data into the DataTable)? Thank you!

sergeyzh free answered 6 years ago


I found a way to do this:
var myData = [{
name: "value",
age: "20"
},{...},...,{...}]
var data = jQuery.map(myData, function (el, i) {
return [
[el.name, el.age]
];
$(document).ready(function () {
$('#dtBasicExample').DataTable({
"aaData": data,
"aoColumns": [{
"sTitle": "Name"
},
{
"sTitle": "Age"
}]
});

Mikołaj Smoleński staff commented 6 years ago

Thanks for publishing Your answer! It might be helpful for other users.

Mikołaj Smoleński staff answered 6 years ago


Hi there, For this moment You can put data inside datatables in two ways: 1) manually using html 2) using php (You can use PHP for statemant) Best Regards

gravey16 free commented 5 years ago

A good enhancement to the plugin would be JSON based a data set option. I didn't see a place to add enhancement ideas, but i could envision something like this. columns[ {field:'firstname', title:'First Name', width:'200', class:'format_class'}, {field:'lastname', title:'Last Name', width:'200', class:'format_class'}, ...... ], data:[{firstname:Jim, lastname:Dugan},{firstname:Steve,lastname:Dawkins }......]

This would be very helpful to people who use database driven tables, as you can simply match the table field names with the Database field names.



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue

  • ForumUser: Free
  • Premium support: No
  • Technology: MDB jQuery
  • MDB Version: 4.5.10
  • Device: PC
  • Browser: Chrome
  • OS: Windows 10
  • Provided sample code: No
  • Provided link: No