Timsen
Timsen

Reputation: 4126

Jqgrid Custom Button

i need to have a send button in my jqgrid. So it means that i have to call An action from my controller when im pressing on the button. Ive got the code for my delete button. but i cant figure out how to send additional data with my action :

gridComplete: function () {
                  var gr = jQuery('#list'); gr.setGridHeight("auto", true);
                  var ids = jQuery("#list").jqGrid('getDataIDs');
                  for (var i = 0; i < ids.length; i++) {
                      var cl = ids[i];
                      be = "<a href='#' style='height:25px;width:120px;' type='button' value='Slet' onclick=\"jQuery('#list').jqGrid('" + cl + "', @Url.Action("Action")); return false;\">Send</>";
                      jQuery("#list").jqGrid('setRowData', ids[i], { act: be });
                  }
              },

Upvotes: 1

Views: 1347

Answers (1)

(Answered in a question edit and comments. Converted to a community wiki answer. See What is the appropriate action when the answer to a question is added to the question itself? )

The OP wrote:

Solved this one by using ajax request

var Send = function (rowId) {
    $.ajax({
        mtype: "POST",
        url: '@Url.Action("Action")',
        data: { actionparameter: rowId },
        async: false,
        cache: false
    });
  };

         gridComplete: function () {
            var gr = jQuery('#list'); gr.setGridHeight("auto", true);
            var ids = jQuery("#list").jqGrid('getDataIDs');
            for (var i = 0; i < ids.length; i++) {
                var cl = ids[i];
                var be = "<a href='#' value='Slet' onclick=\Send(" +cl + "); return false;\">Send</>";
                jQuery("#list").jqGrid('setRowData', ids[i], { act: be });
            }
        },

@Oleg wrote:

You should only

  1. remove async: false which is not needed.
  2. remove cache: false because you use "POST" which is not cached.
  3. replace mtype: "POST" to type: "POST"
  4. replace '=\Send(' to '=\"Send('
  5. You send currently only rowId to the server and no data.

    You did't post the whole grid, so I don't know whether you made local grid editing and the modified data should be send additionally. If you look at the documentation of $.ajax you will find parameter type which default value is "GET". If you write mtype: "POST" it will be ignored like blabla: "HaHa". So the HTTP GET request will be sent where cache: false can have sense, but "POST" could be not allowed in the Action. What you really want was type: "POST". By the way I recommend you to include in your question better too much code as to few. Many things could be more clear and all will save there time

Upvotes: 1

Related Questions