Grid dialog template not to open the dialog if a certain value is not set.

I do not want the dialog template to open on toolbar click "add" if a certain value is not set. How do I prevent the dialog to open? Tried to set grid.endAdd =true in actioncomplete, but it is not working.

4 Replies 1 reply marked as answer

BS Balaji Sekar Syncfusion Team July 1, 2020 05:24 AM UTC

Hi Marie, 
 
Greetings from the Syncfusion support. 
 
We can prevent the add action in DataGrid using actionBegin event. In below code example, we have defined the cancel options is true. it will prevent the add action in Grid. Please refer the below code example for more information 
[Index.cshtml] 
function actionBegin (args) { 
        if (args.requestType == "add") { 
          args.cancel = true; // Prevent the add action 
        } 
      } 
 
Please get back to us, if you need further assistance. 
 
Regards, 
Balaji Sekar 


Marked as answer

MH Marie Hallinan July 1, 2020 07:51 AM UTC

Thank you, that works fine.


MH Marie Hallinan July 1, 2020 02:49 PM UTC

Hi again,
Another question, if there is a possibility to get it to work.
When I press "add" I need to open a dialog where they user needs to input a verification code (this works fine). When the verification dialog opens, we send the user a code via email through ajax and backend. If the code is correct I would like to show the dialog template. Is there a way I can do this? However, if the code is wrong or has expired the dialog should not open.

Regards,
Marie


BS Balaji Sekar Syncfusion Team July 2, 2020 01:35 PM UTC

Hi Marie, 

We have understood your requirement as you want prevent dialog popup while edit a row and get response from the ajax success based to popup that dialog editing. 

We can prevent the edit action using actionBegin event with requesType of “beginEdit” and we have achieved the editing a row from ajax success function using startEdit method of Grid if code is correct. Please refer the below code example for more information. 
[Index.cshtml] 

var hasPrevent = false; 

function actionBegin(args){ 
if(args.requestType == “beginEdit” && !hasPrevent){ 
args.cancel = true; //prevent the editing 

ajax.success: function(res){ 
var grid = document.getElementById('Grid')['ej2_instances'][0]; 
hasPrevent = true; 
grid.startEdit(); // edit a selected row at manually  
  
Please get back to us, if you need further assistance. 

Regards, 
Balaji Sekar 


Loader.
Up arrow icon