jqgrid addRow saveRow beforeSend

5.3k views Asked by At

I have a jqGrid that I am adding a new row to that the user can edit. They have a button to save the new row. I need to get to the ajax beforeSend to stuff some security into the call. This is working in several other scenarios with the grid, but, not this one. Not sure what is going on.

Here is how I am adding the new row:

  jQuery("#myTable").jqGrid('addRow',{
      rowID : "new_row",
      initdata : {},
      position :"first",
      useDefValues : false,
      useFormatter : false,
      addRowParams : {extraparam:{}});

Here is my the code executed by my save button:

      jQuery("#myTable").jqGrid('saveRow',"new_row", {
          "url": "{{path('recording_create')}}",
          "mtype": "POST",
          "succesfunc": function(response) {
              return true; 
          }
      });

I tried this, but, it is not fired. I thought this would be called when saving a row:

$.extend($.jgrid.defaults,                 
                {
                ajaxRowOptions: { 
                    beforeSend: function () {
                        alert('Before Row Send'); // not called
                     }
                    },
                }
            );

I also tried this, but, I think this is only called on form editing?

            $.extend($.jgrid.edit, {
                ajaxEditOptions: {
                    beforeSend: function (jqXHR, settings) {
                        alert('Before Row Send');  // not called
}}});

Any thoughts?

Thanks, Scott

2

There are 2 answers

4
Oleg On BEST ANSWER

You can try to use

$.extend($.jgrid.inlineEdit, {
    ajaxRowOptions: {
        beforeSend: function (jqXHR, settings) {
            alert('Before Row Send');
        }
    }
});

I hope it will work.

UPDATED: Sorry, but the correct code

$.extend($.jgrid.defaults, {
    ajaxRowOptions: {
        beforeSend: function () {
            alert('Before Row Send');
        }
    }
});

you already included in the text of your question. It should work. It's important only to verify that the code will be executed before the grid is created.

0
Doo Dah On

Oleg, Thanks for the idea. But, that did not work. However, the following does work:

    $.ajaxSetup({
        beforeSend: function (jqXHR, settings) {
           alert('Before Row Send');               
      }});

Question for you though, how do you know what can be extended the way you extended above?

Thanks, Scott