datatable ajax data
datatable ajax data
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)
}
})
}