JavaScript UI Libraries & Blazor Components Suite – Smart UI Forums Data Grid addEventListener change produces the event and exports twice.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #104074
    taran naidu
    Participant

    Hi,

    We are exporting on a smart-grid with the help of smart-drop-down-list and every time there is a change the value is picked up and the data is exported on a condition.

    The issue that really occurs is that the event is fired twice and produces two exports for a single event (change of a dropdown value in our case).
    Any idea how this can be resolved?

    Code:

    const gridExport = document.querySelector(‘smart-grid’);

     

    let dropdown = document.createElement(‘smart-drop-down-list’);
    dropdown.id = “dropdownlist”;
    const dropdownExport = document.querySelector(‘#dropdownlist’);

     

    dropdownExport.addEventListener(‘change’, function(event) {
    const detail = event.detail;
    if (detail.value === “Download as spreadsheet”){
    gridExport.exportData(‘xlsx’);
    } else if (detail.value === “Download as CSV file”){
    gridExport.exportData(‘csv’);
    }
    else {
    };
    });

    #104079
    admin
    Keymaster

    Hi taran,

    The “change” event may occur twice or more times in case it is added more than once. The other reason could be that the component is inside another component which raises “change” as well and the event bubbles up.

    Best regards,
    Peter Stoev

    Smart UI Team
    https://www.htmlelements.com/

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.