Storing button indices of multi level buttons

Storing button indices of multi level buttons

trongarttrongart Posts: 222Questions: 51Answers: 0

This in an extension to this discussion.

In this test case, I am using the same global_index variable to store active button filters. The approach as in the previois discussion works well unless a multi level button is used. Filter 1 always has index 0, Filter 2 has index 1, but Filter 3 and 4 that are both inside the multi level Button Group both get index -1.

The index values of the multi level buttons are either the same for all of them as -1 or sometimes 0 and 1 which are the same indices of Filter 1 and 2 and this interferes with them. Thus, activating Filter 3 and then 4, and then deactivating 4 does not work as expected.

How can I make the indices for buttons inside multi level button groups unique to add and remove them from global_index correctly?

This question has an accepted answers - jump to answer

Answers

  • trongarttrongart Posts: 222Questions: 51Answers: 0

    I've made a smaller example: https://live.datatables.net/hoyayubu/1/edit

    Clicking on the filter buttons, you can see the index returned in the console such as $('.filter1').index()

    Filter 1 gets index 0, Filter 2 gets index 1, but Filter 3 and 4 that are both inside the multi level Button Group both get index -1.

    How can Filter 3 and 4 get their own indices that I could use to acess the buttons later?

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

    You can use button().index() to get a unique index for each button. As 3 and 4 are in a collection, they have indexes like "2-1" - see your example updated here: https://live.datatables.net/hoyayubu/3/edit

    Colin

  • trongarttrongart Posts: 222Questions: 51Answers: 0

    This works! Thank you so much @colin

Sign In or Register to comment.