How do I put an AJAX result in the 'render' section of a column?
How do I put an AJAX result in the 'render' section of a column?
Daevin
Posts: 5Questions: 3Answers: 0
I have a table that gets data added to it based on user selection, and in the render section of a column I want to make an AJAX request to check the status of the row added to the table. Right now I have:
columns: [
...
{
data: objectID,
render: function (data, type, full, meta) {
return $.ajax({
url: '/api/CheckStatus?objectID=' + data
}).done(function (data) {
return data.toString()
});
}
},
...
]
which obviously just displays "[object Object]" since it's just returning the AJAX object. Is there a way to have the 'render' portion of a column do this?
This discussion has been closed.
Answers
I'm a little silly. Instead of bothering with promises and other async stuff, I just did this:
In words: I grabbed the desired cell using the cells() API and 'meta' data in the 'render' function, then in the AJAX done() function set the text of that cell to the result of the AJAX call.
It's the most simple way I can think of doing it. If anyone has a better idea, feel free to contribute.