python小菜 2017-01-11 13:19 采纳率: 50%
浏览 27

数据表Ajax渲染

Hi i am trying to create datatable with server side. I can get the data from serverside but i can not add into the columns. Here is my datatable options.

$('#datatable_blog').DataTable({
    responsive : true,
    "oLanguage": {
        "sProcessing": "İşleniyor",
        "sLengthMenu": "Göster _MENU_ veri",
        "sZeroRecords": "Sonuç bulunamadı",
        "sEmptyTable": "Tabloda veri yok",
        "sInfo": "_TOTAL_ veri içinde _START_ 'dan _END_ 'a kadar gösteriliyor",
        "sInfoEmpty": "0 veri içinde 0'dan 0'a kadar gösteriliyor",
        "sInfoFiltered": "_MAX_ veri içerisinden bulunan",
        "sInfoPostFix": "",
        "sSearch": "Bul",
        "sLoadingRecords": "Yükleniyor...",

        "oPaginate": {
            "sFirst": "İlk",
            "sLast": "Son",
            "sNext": "Sonraki",
            "sPrevious": "Önceki"
        }
    },
    "sPaginationType": "full_numbers",
    "aoColumnDefs" : [{
        "bSortable" : false,
        "aTargets" : [ "no-sort" ]
    }],
    "bProcessing": true,
    "bServerSide": true,
    "ajax" : { // define ajax settings
        "url": URL_API + URL_BLOG, // ajax URL
        "type": "GET", // request type
        "dataSrc": "",
        "success": function (response) {
            console.log(response);
        },
        "error": function() { // handle general connection errors }
    },
    "columns": [
        { 
            "blogs": "title", "render": function (data, type, row) {
                console.log(row + data + type);
                return row.title;
            }
        },
        { 
            "data": "Address"
        },
        { 
            "data": "IsActive"
        }
    ]
});

Success console log is :

enter image description here

"columns": [{ 
    "blogs": "title", "render": function (data, type, row) {
        console.log(row + data + type);
        return row.title;
    }
},

Does not any print log. It seems empty. How can i render all returned data into the columns ?

  • 写回答

1条回答 默认 最新

  • weixin_33695082 2017-01-12 08:54
    关注

    Can you try following?

    "columnDefs": [{ 
        "blogs": "title", "render": function (data, type, row) {
            console.log(row + data + type);
            return row.title;
        }
    },
    
    评论

报告相同问题?