1

I've implemented my beautiful jqGrid with multiselect rows so I can delete more than one row at a time.
I've noticed, though, that my action method doesn't work to well with the parameters received:

<HttpPost()> _
Function Delete(ByVal id As List(Of Int32)) As JsonResult

End Function

When I use the delete function of jqGrid.
If I change my parameter in a string that is fine. I can split the string trying to find the comma (,) and everything works properly. But I would like to work clean ;-)
I've found this POST and it seems that jQuery 1.4 has changed the way it posts array. I remember that I had faced a similar situation with an Ajax call passing arrays and the only thing I had to do was to set the traditional parameter to true. Now, what I can I do to have the same feature in jqGrid?

LeftyX
  • 35,328
  • 21
  • 132
  • 193

1 Answers1

2

Delete support ajaxDelOptions parameter which you can use to change options of $.ajax used by jqGrid

$("#myGrid").jqGrid('navGrid', '#pager', {/*navGrid options*/},
    {/*Edit options*/}, {/*Add options*/},
    { // now define settings for Delete dialog
      mtype: "POST", reloadAfterSubmit: false,
      ajaxDelOptions: {traditional: true}
    }
);

Instead of that you can use

$.extend($.jgrid.del, {
    ajaxDelOptions: { traditional: true }
});

to change default options used by jqGrid.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Thanks Oleg. I've tried to put the second fragment of code you've attached but it doesn't seem to work.I've tried to debug with fiddler and it seems that jqGrid's delete with multiselect sends this: oper=del&id=2535%2C2536 – LeftyX Mar 17 '11 at 10:00
  • @LeftyX: I am not sure which format of input data you want to have. Th usage of `traditional: true` was your suggestion. I personally use always the way with `serializeDelData` function which can you define on the same place where `ajaxDelOptions`. The function receive `postdata` as the parameter with all the data which should be send and you can modify the data in any way of convert the data to the any string which should be send to the server and return data which you want to send to the server (the modified `postdata` or the data converted to the string). It's very flexible way and it work – Oleg Mar 17 '11 at 10:13
  • @Oleg, I would like the delete methods of jqGrid to send data so that my MVC controller could be able to bind it as a collection of items. – LeftyX Mar 17 '11 at 10:28
  • @Oleg, I guess mine was a silly question. Forgive me for that. I've tried debug things with fiddler and it seems that jqGrid delete just sends array of deleted rows (with multiselect = true) comma separated. – LeftyX Mar 17 '11 at 10:47
  • 1
    @LeftyX: Yes it is exactly what `traditional: true` should do. You can serialize the array of selected rows as JSON.stringify(selRowids) (inside of `serializeDelData`) and on the server side use `JavaScriptSerializer.Deserialize>` to convert the input string to the list of rowids. MVC 3 must has support of JSON data as the input. In the case you should use `ajaxDelOptions: {contentType: "application/json; charset=utf-8"`}`, then the conversion of the input data will made ASP.NET MVC 3.0 for you directly. – Oleg Mar 17 '11 at 11:05
  • Thanks Oleg.I am using MVC2. Do you have any working example with serializeDelData? Thanks for your great help. – LeftyX Mar 17 '11 at 11:17
  • @LeftyX: I have no such examples. It's very simple. Look at [this answer](http://stackoverflow.com/questions/3587480/jquery-modal-dialog-and-jqgrid) having [the demo](http://www.ok-soft-gmbh.com/jqGrid/DataToMultiSelect2.htm). You should also use `var ids = grid.jqGrid('getGridParam','selarrrow');` to get array of selected ids and use `JSON.stringify(ids)` to return. The code can be about the following: `serializeDelData: function() {return JSON.stringify($("list").jqGrid('getGridParam','selarrrow'))}`. Dont forget include [json2.js](https://github.com/douglascrockford/JSON-js) in the project. – Oleg Mar 17 '11 at 11:48