condition to delete button

condition to delete button

OlanOlan Posts: 41Questions: 11Answers: 1
edited December 2014 in TableTools

i want to have condition to the delete button. It would be nice if it is activated when a condition is met but otherwise only fires the delete action if condition is met is also good. I tried to make my own delete button but I cannot figure out how actually delete the selected row. For now I came up with:

{
         sExtends:    "select_single",
          sButtonText: "MyDeleteButton",
          fnClick:     function( button, config ) {
               var nodedata = this.fnGetSelectedData();
               var status = nodedata[0].standuser.Status;

        if (status === '2'){
            //delete te row
        }               
          }
},

If I put a alert in the if statement, it displayes the alart on the right rows. Now the delete action.....
Hope anybody can help me out with this one.
Thanks!

Answers

  • allanallan Posts: 61,439Questions: 1Answers: 10,053 Site admin

    You could use:

            editor
                    .message( "Are you sure?" )
                    .title( "Delete" )
                    .buttons( "_basic" )
                    .remove( this.fnGetSelectedIndexes() );
    

    (Assuming you are using Editor?).

    Allan

  • OlanOlan Posts: 41Questions: 11Answers: 1
    edited December 2014

    Thank you Allen. Yes, i'm using editor.
    Should I use your code inside my if statement?
    If I do that, i receive the following error:

    TypeError: this.i18n[this.s.action] is undefined
    label: this.i18n[ this.s.action ].submit,

    It 'works' if i have also the original delete button in place, click on it, cancel the delete action and then click on my delete button.

    My code now:

    { sExtends: "editor_remove",
                      editor: editor,
                      sButtonText: "Verwijder",
                      fnClick:     function( button, config ) {
                            var node = this.fnGetSelectedData();
                            var status = node[0].standuser.Status;
    
                            if (status === '2'){
                                editor
                                    .message( "Weet je het zeker om dit te verwijderen?" )
                                    .title( "Delete" )
                                    .buttons( "_basic" )
                                    .remove( this.fnGetSelectedIndexes() );
                            }
                        }
                    },
    

    Thanks!
    Olan

  • OlanOlan Posts: 41Questions: 11Answers: 1

    never mind! This worked! Thanks!

This discussion has been closed.