Build dropdown button menu dynamically
Build dropdown button menu dynamically
![fmcgeough](https://secure.gravatar.com/avatar/7fdf898829d013525c6f621520de3c23/?default=https%3A%2F%2Fvanillicon.com%2F7fdf898829d013525c6f621520de3c23_200.png&rating=g&size=120)
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.