jqgrid addRow saveRow beforeSend

本秂侑毒 提交于 2019-12-08 09:31:22

问题


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


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/11991037/jqgrid-addrow-saverow-beforesend

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!