My code not working dataSrc Please any body help me.
My code not working dataSrc Please any body help me.

//ajax-call:
$(document).ready(function() {
$('#example').DataTable({
ajax: 'api/users',
dataSrc: 'data.table',
columns: [
{ data: 'id' },
{ data: 'firstName' },
{ data: 'lastName' },
],
responsive: true
});
});
//api= response:
[{"id":1,"firstName":"harbhajan","lastName":"sing"},{"id":2,"firstName":"akon","lastName":"bkon"},{"id":3,"firstName":"david","lastName":"warner"},{"id":4,"firstName":"rahul","lastName":"dravid"},{"id":5,"firstName":"sachin","lastName":"tendulkar"}]
//html table:
id | firstName | lastName |
---|---|---|
id | firstName | lastName |
Answers
Looks like two issues. First the
ajax.dataSrc
is to combined with theajax
option. The second isdataSrc: 'data.table',
is not correct since your data is not within an object. Take a look at the second example in theajax.dataSrc
docs for how you should configure this.Kevin
Thanks kthorngren for quick response. i got the answer.
Solution: