editor preOpen event

editor preOpen event

Khalid TeliKhalid Teli Posts: 251Questions: 71Answers: 0

Hi,
I am using an preOpen editor event to disable the editing for rows, if status == Confirmed it returns false as shown in code below and it works fine.

agreementEditor.on( 'preOpen', function ( e )  {
var mode = agreementEditor.mode(); // Gets editor mode, (create, edit, remove)
  console.log(mode);
var modifier = agreementEditor.modifier();  // Gets the selected row of the table

if ( modifier ) {
          var data = agreementTable.row( modifier ).data();
    var status = data.status;
    if (status == "CONFIRMED"){

      alert("You cannot Edit confirmed agreement");

      return false;
    }
}
} );

I am using a Duplicate button like this:

                        extend: "selected",
                        text: 'Duplicate',
                        action: function ( e, dt, node, config ) {
                            agreementEditor
                                .edit( agreementTable.rows( {selected: true} ).indexes(), {
                                    title: 'Duplicate record',
                                    buttons: 'Create from existing'
                                } )
                                .mode( 'create' ); }

How can I make the pre open event to ignore the data.status result . So when I click the Duplicate button it should create rows irrespective of the status of the row.

something like if mode === 'duplicate', ignore this preOpen function??

Thank you

Answers

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin

    Inside the action function for your duplicate button set a variable such as ignore. Then in your event handler check if that was set or not. If set, then reset it and exit.

    Allan

  • Khalid TeliKhalid Teli Posts: 251Questions: 71Answers: 0

    @allan
    Thank you, works perfect.

This discussion has been closed.