row function not working while using .DataTable() to define table.

row function not working while using .DataTable() to define table.

NixxerNixxer Posts: 2Questions: 1Answers: 0
edited November 2018 in Free community support

Hi following is my code, trying 2 get the .row() function working but it keeps returning the not a function error. I could not find any related problems.

$(document).ready(function () {

    // Get the base table element.
    const eventTable = $('#myTable');


    // Initialize the datatable element.
    eventTable.DataTable({
        ajax: '../myjson.json',
        paging: false,
        info: false,
        language: {
            search: '',
            searchPlaceholder: 'naam evenement',
        },
        columns: [
            { "data": "link" },
            { "data": "image" },
            { "data": "event" },
            { "data": "type" },
            { "data": "organiser" },
            { "data": "date" },
            { "data": "time" },
            { "data": "venue" },
            { "data": "city" },
        ],
        columnDefs: [{
            "targets": 0,
            "visible": false,
            "searchable": false,
            "data": "link",
        }]
    });

    // Attach the search filter to the filter section.
    $('div.dataTables_filter').appendTo($('.filter'));

    // Attach the click events.
    eventTable.on('click', 'tr', function () {
        let row = $(this);
        if (row.hasClass('selected')) {
            row.removeClass('selected');
        }
        else {
            $('#myTable tr.selected').removeClass('selected');
            row.addClass('selected');
            let linkData = $('#myTable').row(row).data();
            console.log(linkData);
        }

    });

});

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,112Questions: 1Answers: 2,583
    Answer ✓

    Yep, this

    let linkData = $('#myTable').row(row).data();
    

    should be

    let linkData = $('#myTable').DataTable().row(row).data();
    

    Cheers,

    Colin

  • NixxerNixxer Posts: 2Questions: 1Answers: 0

    Ah mate thanks! was looking too deep into it.

  • Jack_ChasezJack_Chasez Posts: 3Questions: 1Answers: 0

    ¡OMG!..... thanks for that answer so successful :D :D

This discussion has been closed.