Developer
Developer

Reputation: 161

jQuery Datatable render function not working for multiple columns

I am using jQuery Datatable with server side processing, here is my code. It works fine nut as soon as i add one more column for actions button in it, it just stops rendering. Any help will be appreciated.

 $("#table1").dataTable({

        "processing": true,
        "serverSide": true,
        "info": true,
        "lengthMenu": [[5, 35, 50, -1], [5, 35, 50, "All"]],
        "ajax": {
            "url": "/Customer/customers",
            "type": "POST"
        },
        "columns": [
            { "data": "displayName", "orderable": true },
            { "data": "email", "orderable": true },
            { "data": "state", "orderable": true },                
            {
                "data": "licenses", "orderable": true,
                "render": function (data, type, row) {
                    if (type === 'display') {
                        if (data > 0)
                            return '<i class="fa fa-check" aria-hidden="true"></i>';
                        else
                            return '<i class="fa fa-times" aria-hidden="true"></i>';
                    }
                    return data;
                }
            },
        ]           
    });       

Here is another column with action buttons i am adding after licenses in column array.

            {
                "data": null, "orderable": false, "render": function (data, type, row) { return '<a href="' + data + '">Download</a>'; }
            },

Can anyone tell me what is going wrong here?

Upvotes: 1

Views: 1766

Answers (1)

Ishmam Haque Bhuiyan
Ishmam Haque Bhuiyan

Reputation: 66

In the html page, if you have less or columns than the number of columns that you are rendering using ajax, it will show error. As you are saying that it shows error when one more column is added, I think the issue is that there is less column in your html page. If you fix the number of columns, I think it will work.

Upvotes: 1

Related Questions