Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 81917

$.each in render function

$
0
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 ?


Viewing all articles
Browse latest Browse all 81917

Trending Articles