Error with render on column

Error with render on column

titechnotitechno Posts: 16Questions: 5Answers: 0

Debugger code (debug.datatables.net):

https://debug.datatables.net/erevic

Error messages shown:

DataTables warning: table id=autohausGruppen - Requested unknown parameter 'Autohaus_Gruppen.gemeldet' for row 0, column 2. For more information about this error, please see http://datatables.net/tn/4

Description of problem:

When loading the table the above mentioned error message appears.
When commenting out the "render" part of the code the data is displayed normaly.
Do you guys have any idea where my problem is?
The code inside the render function is runing without a problem, the error appears after the function concluded.
Even the table loads normal.
I tried data: null but the same error appears only for unknown parameter 'null'.

Problematic code:

{
        data: "Autohaus_Gruppen.gemeldet",
        className: "dt-center",
        //defaultContent: '<i class="fa fa-check"/>',
        render: function (data,type, row, meta) {
            if (data.Autohaus_Gruppen.gemeldet != null && data.Autohaus_Gruppen.gemeldet == 1)
            {
                return '<i class="fa fa - check"/>';
            }
        },
        orderable: false,
        width: "5%"
},

Answers

  • titechnotitechno Posts: 16Questions: 5Answers: 0
    edited January 2022

    Nvm. somehow it now works just like this (I'm almost certain I tried this first but oh well sometimes it is what it is):

    {
                    data: "Autohaus_Gruppen.gemeldet",
                    className: "dt-center",
                    defaultContent: '',
                    render: function (data,type, row, meta) {
                        if (data != null && data == 1)
                        {
                            return '<i class="fa fa-check"/>';
                        }
                    },
                    orderable: false,
                    width: "5%"
                },
    
  • kthorngrenkthorngren Posts: 21,352Questions: 26Answers: 4,955

    Using defaultContent will work. However the problem is that the columns.render function always needs to return something. You are returning something only if your data == 1. The function should look like this:

                    render: function (data,type, row, meta) {
                        if (data != null && data == 1)
                        {
                            return '<i class="fa fa-check"/>';
                        }
                        return '';
                    },
    

    Kevin

Sign In or Register to comment.