Use API deselect method without triggering deselect event

Use API deselect method without triggering deselect event

Loren MaxwellLoren Maxwell Posts: 406Questions: 99Answers: 10
edited February 2022 in DataTables 1.10

This might be more of a JavaScript or jQuery question, but I came here because you guys are the nicest and most handsome folks on the internet :-)

I'm working on the interaction between multiple tables where only one row can be selected among all the tables.

When I select a row in one table, I use that select event to deselect() the rows in all the other tables:

newly_selected_table.on("select", function ( e, dt, type, indexes ) {
    deselect rows in all the other tables using the API
})

As expected this triggers the deselect event for each of those newly deselected rows, which I use to close the child rows:

previously_selected_table.on("deselect", function ( e, dt, type, indexes ) {
    close child rows
})

However there's a specific circumstance where I want to deselect the other row without triggering the deselect event so that the child rows remain open.

I tried calling an empty function to override the deselect event above, but it didn't work:

newly_selected_table.on("select", function ( e, dt, type, indexes ) {
    if (not special circumstance) {
        previously_selected_table.rows().deselect()
    } else special circumstance {
        previously_selected_table.rows().deselect(function(){
            return false
        })
    }
})

Is something like that possible?

This question has accepted answers - jump to:

Answers

  • kthorngrenkthorngren Posts: 21,322Questions: 26Answers: 4,948
    Answer ✓

    Can you check the "circumstance" in the deselect event to determine if the child rows should be closed?

    Kevin

  • Loren MaxwellLoren Maxwell Posts: 406Questions: 99Answers: 10

    Thanks, Kevin (@kthorngren) , I can create a separate variable that will do that, but I was just hoping to avoid that if I could override the deselect function somehow.

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    Answer ✓

    Yep, the variable would probably be the easiest, unless it's something codable.

    And I'm pleased that our grooming regime is being appreciated ;)

    Colin

  • Loren MaxwellLoren Maxwell Posts: 406Questions: 99Answers: 10
    edited February 2022

    Thanks, @colin and @kthorngren,

    Ultimately I just did something like this:

    function close_child_row(row) {
        close child row
    }
    
    newly_selected_table.on("select", function ( e, dt, type, indexes ) {
        if (not special circumstance) {
            close_child_row(previously_selected_table's open row)
        }
        previously_selected_table.rows().deselect()
    })
    
Sign In or Register to comment.