datatable ajax data
datatable ajax data
chiro
Posts: 16Questions: 8Answers: 0
Hi.
I replaced function ajax with a datatable.
$(document).ready(function() {
getUserList();
}
function getUserList(){
$.ajax({
url : "userList.json",
success:function(data){
var html = '';
for(key in data){
html += '<tr>';
html += '<td>'+data[key].name+'<td>';
html += '<td>'+data[key].email+'<td>';
html += '<tr>';
}
$("#div").empty();
$("#div").append(html)
}
})
}
I have succeeded in changing the source above as below.
$(document).ready( function () {
var table = $( '#userTable' )
.addClass( 'nowrap' )
.dataTable( {
responsive: true,
ajax: {
'url': 'userList.json’,
'dataSrc': ''
},
columns: [
{'data': 'name'},
{'data': 'email'}
]
} );
} );
But I don't know how to change the data in the source below...
Where should I add something to my data table?
var global_UserOrder = null;
$(document).ready(function() {
global_UserOrder = order;
getUserList();
}
function getUserList(order){
global_UserOrder = order;
$.ajax({
//this
data : {
order : order,
},
//
url : "userList.json",
success:function(data){
var html = '';
for(key in data){
html += '<tr>';
html += '<td>'+data[key].name+'<td>';
html += '<td>'+data[key].email+'<td>';
html += '<tr>';
}
$("#div").empty();
$("#div").append(html)
}
})
}
Thanks. ^--------^
This question has accepted answers - jump to:
This discussion has been closed.
Answers
I'm not following, sorry. The middle example would load the data into the DataTable - I'm not sure what you're trying to do.
Colin
I succeeded in replacing the first example with the second.
I want to replace the third example with a datatable like the second.
I don't know how to do this
data : {
order : order,
},
thanks your reply
You should read through the
ajax
docs. It states:And points you to using
ajax.data
. The examples show how to add static data or adding dynamic data using a function.Kevin
I finally succeeded.
Not this ↓
.dataTable( {
ajax: {
In the third example, run the datatable inside success: function (data)
thanks your reply ^___^