Adding buttons to a collection creates ordinary buttons within

Adding buttons to a collection creates ordinary buttons within

veer8veer8 Posts: 1Questions: 1Answers: 0
edited August 2018 in Free community support

/*! Buttons for DataTables 1.5.2
* ©2016-2018 SpryMedia Ltd - datatables.net/license
*/

I have a Buttons configuration like this:

{
 name: 'buttonsRight'
 buttons: [
   {
      extend: "collection",
      text: "…"
      name: 'someDropDown',
      buttons: [],
      postfixButtons: [
         {}…
      ],
      …
   }
 ]
}

Later, after doing an async load for the contents, I continue to populate 'someDropdown':

var button = api.button('buttonsRight', 'someDropDown:name');
for(…) {
  button.add('0-null', {
    text: "…",
    action: (…) => {…}
  })
}

What happens, is that the collection button will get the buttons added to it, but they will not have their inCollection property set, and their inserters will be normal. I.e., normal buttons appear in the dropdown instead of list items. I was expecting the new button to have inCollection = true and draw as a list item.

The button node's add function that eventually gets invoked (line 144) curiously always expands with inCollection = false. ( refer to https://github.com/DataTables/Buttons/blob/fd325d6a3af34dd45253205df0349d5ca3324b0e/js/dataTables.buttons.js#L160).

Replacing the false with an 'base !== undefined' expression gives me the result I want, but I could be naively breaking DT's internals; it superficially appears to work for my application. I have not grokked Buttons in its entirety.

To work around this, I'm delaying the init to the async callback in order to avoid dynamically modifying the collection. Am I using add incorrectly, or is this a genuine defect?

Thanks!

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin
    Answer ✓

    Hi,

    You are absolutely correct - great analysis. Thank you.

    This is a genuine defect and I've logged it as such to be addressed for the next release of Buttons.

    Regards,
    Allan

This discussion has been closed.