dynamically assign different editor to a button based on row value
dynamically assign different editor to a button based on row value
I defined two editors: editor1 and editor2. I want to the "edit" button "refer" to the correct editor based on the value of the selected row. So that the "edit" button will open a different edit form based on some value of that row.
I did some thing like this, but does not work, please help.
...
buttons: [
{extend: "create", editor: createEditor},
{extend: "edit", editor: editor1},
...]
table.rows({selected: true}).every( function ( rowIdx, tableLoop, rowLoop ) {
var data = this.data();
if ( data.status == 'something' ) {
table.button( 1 ).editor= editor1
}
else{
table.button( 1 ).editor= editor2
}
});
Answers
I don't think there is a way to change the button assignments like that.
One option is to use
button().remove()
to remove theeditor1
, for example, buttons then usebutton().add()
to add theeditor2
buttons.Another option is to create all the Editor buttons and use
buttons.buttons.className
to assign a class to theeditor2
buttons to hide them. Then usebutton().node()
to add and remove the class appropriately to display the proper set of buttons.Kevin
Another option is to use the
action
for the button itself. Here the action is doing a duplication. Instead you could calledit()
with the preferred Editor instance.Colin