Remove collection when there are no more buttons present in the collection

Remove collection when there are no more buttons present in the collection

ctmlctml Posts: 28Questions: 10Answers: 0

Link to test case:

Problem/Question:
Remove all collection sub buttons, leave parent.
https://jsfiddle.net/m1Leztu6/16/

Issue/bug:
Remove all collection sub buttons including parent (layout issue)
https://jsfiddle.net/m1Leztu6/13/

Under this second test case with Bootstrap 4 styling, removing a button does not remove the parent btn-group div which impacts layout of the remaining buttons. I am dynamically removing the buttons based on attributes of the button.

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

I would like to try to under the first test marked problem/question leave the parent button but then after removing the collections buttons check to see if there are any remaining buttons in the collection, and if not then remove the parent button. However I could not find any function to retrieve a collections parent, and the associated children buttons in the collection to do that, or any link to the parent button from the child button being removed. Is it possible to achieve what I am trying to do?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 64,230Questions: 1Answers: 10,599 Site admin

    after removing the collections buttons check to see if there are any remaining buttons in the collection, and if not then remove the parent button.

    It feels a little on the hacky side, it is possible if you know the parent button's index. The idea is that you simply request the first sub button for that index - if it doesn't work, an error will be thrown, so you can do a try / catch:

    try {
      table.button('0-0');
    }
    catch (e) {
      // There is no sub-button, so can remove the parent
      table.button('0').remove();
    }
    

    Might be nicer if the API provided a way to handle this. I'll consider how that might be done.

    Allan

  • ctmlctml Posts: 28Questions: 10Answers: 0

    Thanks Allan. And for the removal of button leaving an orphaned btn-group div, would you consider that a bug? Unfortunately it breaks the button layout.

    Issue/bug:
    Remove all collection sub buttons including parent (layout issue)
    https://jsfiddle.net/m1Leztu6/13/

  • allanallan Posts: 64,230Questions: 1Answers: 10,599 Site admin
    Answer ✓

    Sorry, yes, I missed that point. I totally agree, that's a bug. Fix committed here.

    Allan

Sign In or Register to comment.