0

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

Doo Dah
  • 3,979
  • 13
  • 55
  • 74

2 Answers2

2

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.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • @ScottV: I tested and the code `$.extend($.jgrid.defaults, {ajaxRowOptions: {beforeSend: function () {alert('Before Row Send');}}});` do work. [The line](https://github.com/tonytomov/jqGrid/blob/v4.4.0/js/grid.inlinedit.js#L324) of inline editing code uses `$t.p.ajaxRowOptions` which is the `ajaxRowOptions` parameter of jqGrid. One can set it by `$.extend($.jgrid.defaults,{ajaxRowOptions: {...}});` – Oleg Aug 16 '12 at 19:55
  • Ok. If I set this as a grid param, like, ajaxRowOptions: { contentType: "application/json" }, ajaxRowOptions: { contentType: "application/json", beforeSend: function () { debugger; alert('Before Row Send'); } }, it works. But, if I try extending as you say, it does not work. Either way, the solution is to use ajaxRowOptions – Doo Dah Aug 16 '12 at 21:10
  • 1
    @ScottV: Probably you created the grid *before* calling of `$.extend($.jgrid.defaults, ...);`? I don't understand why the setting of `$.jgrid.defaults` should be ignored. – Oleg Aug 16 '12 at 21:15
  • @ScottV: OK! Then everything will be clear. I included the "UPDATED" part in my answer for other readers only. – Oleg Aug 16 '12 at 22:01
0

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

Doo Dah
  • 3,979
  • 13
  • 55
  • 74