jqgrid addRow saveRow beforeSend

2019-06-08 20:47发布

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条回答
霸刀☆藐视天下
2楼-- · 2019-06-08 21:17

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

查看更多
▲ chillily
3楼-- · 2019-06-08 21:26

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.

查看更多
登录 后发表回答