Way to tell if select event came from mouse click or programmatically?

Way to tell if select event came from mouse click or programmatically?

BarryBBarryB Posts: 4Questions: 1Answers: 0

Using $('#myTable').DataTable().on('select', function (e, dt, type, indexes) to capture select events.

However, I populate the table initially from external data where some rows are already selected. I only want to know when the user takes action i.e. clicks. Looked through all the arguments but nothing seemed obvious.

Thanks in advance!

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954
    Answer ✓

    Use the user-select event for this.

    Kevin

  • BarryBBarryB Posts: 4Questions: 1Answers: 0

    Thanks this basically works. This event appears to fire before the select/deselect events, so I look at the originalEvent to determine what the semantic is:

        $('#myTable').DataTable().on('user-select', function (e,dt,type,cell,OriginalEvent)      
        {
            var sel1 = originalEvent.target.parentNode.classList.contains("selected");
            if (sel1 === true)
                console.log("deselecting");
            else
                console.log("selecting");
        });
    

    Sort of feels a little hacky ... not sure there's a better way though.

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954

    This thread has a similar comment with one of the developer's responses.

    Kevin

  • BarryBBarryB Posts: 4Questions: 1Answers: 0

    Thanks. Posted a comment there.

This discussion has been closed.