select give an Error

select give an Error

Andreas S.Andreas S. Posts: 207Questions: 73Answers: 4

Hi,

If I select or deselect in the list a row I get following error.

SCRIPT5007: Unable to get property 'node' of undefined or null reference

Here are my code, but did not see any faults. May you have a hint for me where my failure
is?

Andreas

$( document ).ready( function() {
    $( 'body' ).data( 'userSetting' ).done( function( data ) {
        var i18n_lng = data.language;
        var i18n_url = getLanguage( i18n_lng );
        var uLevel = data.u_Level;
        var cID = data.showCuid
        var pool = getUrlVar( 'epo' );
        var ajaxurl;
        var dtButtons = [];

        if( 6 == uLevel || 5 == uLevel ) {
            if( '' != pool ) {
                ajaxurl = '/lib/adm/meet-api.php?mmap=4&epo=' + pool + '&emt=i';
            } else {
                ajaxurl = '/lib/adm/meet-api.php?mmap=4';
            }
            var isTarget7 = true;
            var isTarget8 = true;

            var btShowMeet = true;
            var btEnableEntry = true;
            var btAddAthlete = true;
            var btAddRelay = true;
            var btShowCost = true;
            var btListEntries = false;
            var btEntrySum = false;
        } else if( 4 == uLevel ) {
            ajaxurl = '/lib/adm/meet-api.php?mmap=4';
            var isTarget7 = false;
            var isTarget8 = false;

            var btShowMeet = false;
            var btEnableEntry = false;
            var btAddAthlete = true;
            var btAddRelay = true;
            var btShowCost = true;
            var btListEntries = false;
            var btEntrySum = true;
        }

    //  ajaxurl = 'lib/adm/meet-api.php?mmap=1';
        var isTarget1 = true;

        if( true == btShowMeet ) {
            dtButtons.push( {
                text: '<i class="fas fa-eye fa-fw"></i>',
                titleAttr: button_txt[0],
                className: 'text-olive',
                action: function( e, dt, node, config ) {
                    var data = mt_ls.row( { selected: true } ).data();
                    $.post({
                        url: 'lib/adm/meet-api.php?mmap=2&uuid=' + data.DT_RowId
                    })
                    .done( function( data ) {
                        var notify = ( undefined == data.title ) ? JSON.parse( data ) : data;
                        pNotify( notify.title, notify.text, notify.icon, notify.type );
                        mt_ls.ajax.reload();
                    });
                },
                enabled: false
            } );
        }

        if( true == btEnableEntry ) {
            dtButtons.push( {
                text: '<i class="fas fa-wrench fa-fw"></i>',
                titleAttr: button_txt[1],
                className: 'text-maroon',
                action: function( e, dt, node, config ) {
                    var data = mt_ls.row( { selected: true } ).data();
                    $.post( {
                        url: 'lib/adm/meet-api.php?mmap=3&uuid=' + data.DT_RowId
                    } )
                    .done( function( data ) {
                        var notify = ( undefined == data.title ) ? JSON.parse( data ) : data;
                        pNotify( notify.title, notify.text, notify.icon, notify.type );
                        mt_ls.ajax.reload();
                    });
                },
                enabled: false
            } );
        }

        if( true == btAddAthlete ) {
            dtButtons.push( {
                text: '<i class="fas fa-user-plus fa-fw"></i>',
                titleAttr: button_txt[2],
                className: 'text-green',
                action: function( e, dt, node, config ) {
                    var data = mt_ls.row( { selected: true } ).data();
                    var meetType = ( 'INVITATION' == data.contentType ) ? 'i' : ( ( 'ENTRIES' == data.contentType ) ? 'e' : 'r' );
                    var set = $.post( '/lib/adm/setvar.php', { mid: data.DT_RowId, cot: meetType, cid: cID, back: 'mtlst' } );
                    set.done( function() {
                        location.assign( '/index.php?mo=listE&me=lsath' );
                    } );
                },
                enabled: false
            } );
        }

        if( true == btAddRelay ) {
            dtButtons.push( {
                text: '<i class="fas fa-users fa-fw"></i>',
                titleAttr: button_txt[3],
                className: 'text-blue',
                action: function( e, dt, node, config ) {
                    var data = mt_ls.row( { selected: true } ).data(); 
                    var set = $.post( '/lib/adm/setvar.php', { mid: data.DT_RowId, cid: cID, cot: 'i', back: 'mtlst' } );
                    set.done( function() {
                        location.assign( '/index.php?mo=listE&me=lsrel' );
                    } );
                },
                enabled: false
            } );
        }

        if( true == btShowCost ) {
            dtButtons.push( {
                text: '<i class="fas fa-money-bill fa-fw"></i>',
                titleAttr: button_txt[3],
                className: 'txt-MediumPurple ml-10',
                action: function( e, dt, node, config ) {
                    var data = mt_ls.row( { selected: true } ).data(); 
                    var set = $.post( '/lib/adm/setvar.php', { mid: data.DT_RowId, cid: cID, back: 'mtlst' } );
                    set.done( function() {
                        location.assign( '/index.php?mo=listE&me=mtcost' );
                    } );
                },
                enabled: false
            } );
        }

        if( true == btListEntries ) {
            dtButtons.push( {
                text: '<span class="fa-layers fa-fw"><i class="fal fa-square"></i><span class="fa-layers-text fa-inverse text-blue" data-fa-transform="grow-2" style="font-weight:900">E</span></span>',
                titleAttr: button_txt[4],
                className: 'text-white ml-10',
                action: function( e, dt, node, config ) {
                    var data = mt_ls.row( { selected: true } ).data();
                    var set = $.post( '/lib/adm/setvar.php', { mid: data.DT_RowId, cid: cID, cot: 'i', back: 'mtlst' } );
                    set.done( function() {
                        location.assign( '/index.php?mo=listE&me=colsath' );
                    } );
                },
                enabled: false
            } );
        }

        if( true == btEntrySum ) {
            dtButtons.push( {
                text: '<i class="fas fa-print fa-fw"></i>',
                titleAttr: button_txt[4],
                className: 'text-red ml-10',
                action: function( e, dt, node, config ) {
                    var data = mt_ls.row( { selected: true } ).data();
                    var set = $.post( '/lib/adm/setvar.php', { mid: data.DT_RowId, cid: cID, cot: 'i', back: 'mtlst' } );
                    set.done( function() {
                        location.assign( '/index.php?mo=listE&me=entsum' );
                    } );
                },
                enabled: false
            } );
        }

        var mt_ls = $( '#mt_lst' ).DataTable( {
            language: {
                url: i18n_url
            },
            ajax: {
                url: ajaxurl,
                type: 'POST',
                dataSrc: 'content'
            },
            autoWidth: false,
            select: true,
            serverSide: true,
            processing: true,
            dom: "<'row'<'col-sm-4'l><'col-sm-4 DT_Buttons_Style'B><'col-sm-4'f>>rt<'row'<'col-sm-6'i><'col-sm-6'p>>",
            columnDefs: [
                { targets: 0, visible: true },
                { targets: 1, visible: isTarget1 },
                { targets: 2, visible: true },
                { targets: 3, visible: true, searchable: true, orderable: true },
                { targets: 4, visible: true },
                { targets: 5, visible: true },
                { targets: 6, visible: true },
                { targets: 7, visible: isTarget7 },
                { targets: 8, visible: isTarget8 },
                { targets: '_all', visible: false, searchable: false, orderable: false }
            ],
            columns: [
                {
                    data: '_index', width: '1.5%', className: 'text-center'
                },{
                    data: 'contentType', width: '1.5%', render: function( data, type, row ) {
                        return ( 'INVITATION' == data ) ? '<span class="text-Crimson">I</span>' : ( ( 'ENTRIES' == data ) ? '<span class="text-olive">E</span>' : '<span class="text-finsw">R</span>' );
                    }, className: 'text-center'
                },{
                    data: 'period', width: '13%', className: 'text-right'
                },{ 
                    data: 'name'
                },{
                    data: 'location', render: function( data, type, row ) {
                        if( 'display' === type ) {
                            var $lng = ( 'de' == i18n_lng ) ? data.nameGerman : data.nameEnglish;
                            if( '' == data ) {
                                return '';
                            } else {
                                if( '' != data.alpha2 && null != data.alpha2 ) {
                                    var flag = '<span class="flag-icon flag-icon-' + data.alpha2.toLowerCase() + '" title="' + $lng + '"></span>&nbsp;&nbsp;';
                                } else {
                                    var flag = '';
                                }
                                return flag + data.city;
                            }
                        } else {
                            return data.ioc + ' ' + data.city;
                        }
                    }
                },{
                    data: 'course', width: '1%', className: 'text-center'
                },{
                    data: 'deadline', width: '11%', className: 'text-center fs-13'
                },{
                    data: 'enabled', render: function( data, type, row ) {
                        return ( true == data ) ? '<i class="fas fa-eye text-green"></i>' : '<i class="fas fa-eye-slash text-Tomato"></i>'
                    }, className: 'text-center'
                },{
                    data: 'entryEnabled', render: function( data, type, row ) {
                        return ( true == data ) ? '<i class="fas fa-wrench text-green"></i>' : '<i class="fas fa-wrench text-Tomato"></i>'
                    }, className: 'text-center'
                }
            ],
            buttons: dtButtons,
            pagingType: 'numbers',
            initComplete: function( data ) {
                $( '#mt_lst' ).removeClass( 'hidden' );
            }
        } );

        mt_ls.on(
            'select', function () {
                var selectedRows = mt_ls.rows( { selected: true } ).count();
                if( 6 == uLevel || 5 == uLevel ) {
                    mt_ls.button( 0 ).enable( selectedRows === 1 );
                    mt_ls.button( 1 ).enable( selectedRows === 1 );
                    mt_ls.button( 2 ).enable( selectedRows === 1 );
                    mt_ls.button( 3 ).enable( selectedRows === 1 );
                    mt_ls.button( 4 ).enable( selectedRows === 1 );
                    mt_ls.button( 5 ).enable( selectedRows === 1 );
                } else if ( 4 == uLevel ) {
                    mt_ls.button( 0 ).enable( selectedRows === 1 );
                    mt_ls.button( 1 ).enable( selectedRows === 1 );
                    mt_ls.button( 2 ).enable( selectedRows === 1 );
                    mt_ls.button( 3 ).enable( selectedRows === 1 );
                    mt_ls.button( 4 ).enable( selectedRows === 1 );
                }
            } );

            mt_ls.on(
            'deselect', function() {
                var selectedRows = mt_ls.rows( { selected: true } ).count();
                if( 6 == uLevel || 5 == uLevel ) {
                    mt_ls.button( 0 ).disable( selectedRows === 0 );
                    mt_ls.button( 1 ).disable( selectedRows === 0 );
                    mt_ls.button( 2 ).disable( selectedRows === 0 );
                    mt_ls.button( 3 ).disable( selectedRows === 0 );
                    mt_ls.button( 4 ).disable( selectedRows === 0 );
                    mt_ls.button( 5 ).disable( selectedRows === 0 );
                } else if( 4 == uLevel ) {
                    mt_ls.button( 0 ).disable( selectedRows === 0 );
                    mt_ls.button( 1 ).disable( selectedRows === 0 );
                    mt_ls.button( 2 ).disable( selectedRows === 0 );
                    mt_ls.button( 3 ).disable( selectedRows === 0 );
                    mt_ls.button( 4 ).disable( selectedRows === 0 );
                }
            } );

    } );
} );

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,118Questions: 1Answers: 2,583

    Hi @Andreas S. ,

    That's a lot of code there. We're happy to take a look, but it would help, as per the forum rules, if you could link to a running test case showing the issue so we can offer some help. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • Andreas S.Andreas S. Posts: 207Questions: 73Answers: 4

    I have send Allan a link to my test environment. go to Meets/Meet Overview and you see the problem

    Andreas

  • allanallan Posts: 61,452Questions: 1Answers: 10,055 Site admin
    Answer ✓

    You have:

    mt_ls.button( 5 ).enable( selectedRows === 1 );

    But there is no button 5, so Buttons is correctly throwing an error. There are 5 buttons and it is zero indexed.

    Allan

  • Andreas S.Andreas S. Posts: 207Questions: 73Answers: 4

    thanks, Allan

This discussion has been closed.