Build dropdown button menu dynamically

Build dropdown button menu dynamically

fmcgeoughfmcgeough Posts: 3Questions: 1Answers: 0

I have an array of strings that define buttons. I'd like to dynamically create those buttons in a DataTable table. for example, suppose I have an array ["item1", "item2"]. What I want in the datatable buttons definition is:

`  extend: 'collection',
  text: "Add Item <span class=\"caret\">",
  buttons: [
    {
      text: 'item1',
      action: function ( e, dt, node, config ) {
        window.location.href = href + "/items/new?name=item1";
      }
    },
    {
        text: 'item2',
        action: function ( e, dt, node, config ) {
          window.location.href = href + "/items/new?name=item2";
        }
    }
  ]
`

how would I go about doing this dynamically? The server is giving me a JSON array of the strings above. Now I need to build my buttons.

This discussion has been closed.