-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Process Ajax Data Before Displaying on Table! #39
Comments
You cannot do this with the AJAX option directly but you can do it manually by first creating an empty table (just pass an empty array as the var dt = new DataTable(myTableId, {
data: [],
// Other options...
});
function fetchData() {
var originalData = /* ... */;
// Returns an array of data:
var processedData = processData(originalData);
// Add the new entries to the table:
dt.addRows(processData);
// $(myTableId).datatable('insert', processedData);
} |
Hi! Here is my code function Init(){
dt = new DataTable(document.getElementById('orders'), {
data: [],
prevPage: false,
nextPage: false,
onChange: function (old, current) {
//alert(old + "," + current);
if (current > old) {
//GetOrders(current, limit, accessToken);
}
},
lineFormat: function (id, data) {
var res = $('<tr></tr>');
for (var key in data) {
res.append('<td>' + data[key] + '</td>');
}
return res;
},
} But, I got the following error, it seems like something is wrong with "lineFormat". Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.
at DataTable.refresh (datatable.min.js:1)
at DataTable.filter (datatable.min.js:1)
at DataTable.sort (datatable.min.js:1)
at DataTable.addRows (datatable.min.js:1)
at UpdateUI (Index:204)
at Object.<anonymous> (Index:153)
at fire (jquery-1.10.2.js:3062)
at Object.fireWith [as resolveWith] (jquery-1.10.2.js:3174)
at done (jquery-1.10.2.js:8249)
at XMLHttpRequest.callback (jquery-1.10.2.js:8792) |
The problem is that you are mixing jQuery with the native datatable constructor. Your lineFormat: function (id, data) {
var res = document.createElement('tr');
for (var key in data) {
res.innerHTML += '<td>' + data[key] + '</td>';
}
return res;
} Or you need to construct the datatable with jQuery: $('#orders').datatable({
});
$('#orders').datatable('insert', [...]); |
I'm consuming data from a web service/API.
When the response is arrived, I have to iterate over the list, fetch some data of interest, build new array of data then show the array on the datatable.
How can I achieve this using ajax option?
The text was updated successfully, but these errors were encountered: