$.each in render function
$.each in render function
xKushGene
Posts: 2Questions: 2Answers: 0
I want to Convert my column.data. So I load the results from the convert before i call the table to load:
function test(){
return $.ajax({
url: "../api.php?getGroups",
type: "Get",
dataType: 'json',
success: function(data) {
console.log(data);
}
});
}
// Load Table Data
$(document).ready(function() {
$.when(test()).done(function(a1){
var table = $('#customerTable').DataTable({
"ajax": {
"url": "../api.php?getUsers&type=kunden",
"type": "GET",
"dataSrc": ""
},
"columns": [
{
// Format Date
"data" : "created_at",
render: function(data) {
return moment(data).format('LLL')
}
},
{
// Convert Usergroup
"data" : "usergroup",
render: function(data){
$.each(a1, function(i, v) {
if(v.id == data){
return v.groupname;
}
});
},
"defaultContent": "<i>Not Set</i>"
},
[....]
But the $.each
doesn't work. Everytime i will get the "defaultContent"
. How can I return $.each
results inside render
?
This discussion has been closed.
Answers
Without knowing what the content of
a1
is, I can't fully say. However, my guess is that the issue is your arereturn
ing from inside the$.each
function (i.e. an inner anonymous function) rather than the rendering function. You should assign the matched value to a variable and then return that from outside the$.each
.Allan