Uncaught TypeError: Cannot read property 'isActive' of undefined

Uncaught TypeError: Cannot read property 'isActive' of undefined

othmanjadallahothmanjadallah Posts: 2Questions: 1Answers: 0

i have a problem
i need make a text base on database value in asp.net zero
im send the value from service to datatable but im see the message error same in the title
this my code

var getFilter = function () {

    var filter = {
        programName: $("#InstitutionFilter").val(),
        programType:  $("#InstitutionFilter").val(),
        InstitutionName:  $("#InstitutionFilter").val()
    };
    return filter;
}
         var _programService = abp.services.app.program;
        var _$programsTable = $("#ProgramsTable");
        var dataTable = _$programsTable.DataTable({
        paging: true,
        serverSide: true,
        processing: true,
        listAction: {
            ajaxFunction: _programService.getPrograms,
            inputFilter: function () {
                return getFilter();
            }
        },
        columnDefs: [
            {
                className: 'control responsive',
                orderable: false,
                render: function () {
                    return '';
                },
                targets: 0
            },

            {
                targets: 1,
                data: null,
                orderable: false,
                autoWidth: false,
                defaultContent: '',
                rowAction: {
                    text: '<i class="fa fa-cog"></i> ' + app.localize('Actions') + ' <span class="caret"></span>',
                    items: [
                        {
                            text: function (data) {
                                if (data.record.isActive) {
                                    return "DisActive"
                                } else {
                                    return "Active"
                                }
                            },

                            action: function () {

                            }
                        },    {
                            text: app.localize('Delete'),
                            visible: function () {

                            },
                            action: function () {

                            }
                        }
                    ]

                }
            },
            {
                targets: 2,
                data: "programName"
            },
            {
                targets: 3,
                data: "programType"
            },   {
                targets: 4,
                data: "institutionName"
            }
        ]
        });

 function getProgram() {
        dataTable.ajax.reload();
    }

Answers

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951
    edited December 2019

    As far as I know Datatables doesn't have a configuration option rowAction. I'm not familiar with what it is doing but the error suggests the problem is here:

                                text: function (data) {
                                    if (data.record.isActive) {
                                        return "DisActive"
                                    } else {
                                        return "Active"
                                    }
                                },
    

    Specifically data.record.isActive. Sounds like the error is indicating data.record is undefined. Does data have the property record? You can try using console.log( data ); inside that function to see what data contains.

    Kevin

This discussion has been closed.