Avoid .on( 'draw.dt', initMap ); in Datatable

Avoid .on( 'draw.dt', initMap ); in Datatable

MausinoMausino Posts: 61Questions: 19Answers: 0
edited April 2023 in DataTables 1.10

Link to test case:

Hi, i want initialize .on( 'draw.dt', initMap ); only for core search function in DataTables but not for hideMarkers() function. It is possible somehow avoid it or detect if core search was used in DataTable?

$(document).ready(function () {

    var table = $('#example').DataTable().on( 'draw.dt', initMap );

   function  hideMarkers(marker) {

    $.fn.dataTable.ext.search.push(function (settings, data, dataIndex) {

    if (marker === 'visible') {
        return true;
    } 
        return false;
    });

    // here i want somehow avoid initMap in example DataTable but don't know
    $('#example').DataTable().draw();

   }
});

Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,573Questions: 1Answers: 10,483 Site admin
    Answer ✓

    You'd need to set a flag in your hideMarkers function. One which your initMap function can also access. Then in initMap check if the flag is set or not to determine if hideMarkers triggered the draw.

    Allan

Sign In or Register to comment.