dynamically assign different editor to a button based on row value

dynamically assign different editor to a button based on row value

zyq105zyq105 Posts: 17Questions: 4Answers: 0
edited February 2022 in Editor

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

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951

    I don't think there is a way to change the button assignments like that.

    One option is to use button().remove() to remove the editor1, for example, buttons then use button().add() to add the editor2 buttons.

    Another option is to create all the Editor buttons and use buttons.buttons.className to assign a class to the editor2 buttons to hide them. Then use button().node() to add and remove the class appropriately to display the proper set of buttons.

    Kevin

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Another option is to use the action for the button itself. Here the action is doing a duplication. Instead you could call edit() with the preferred Editor instance.

    Colin

Sign In or Register to comment.