0

I want to delete multiple rows in my grid, but when I select multiple rows and click on the delete button, nothing happens. No parameters are passed to the editurl!

please help. Here is my code for the delete options inside navGrid:

{height:180,mtype:"POST",closeAfterDel:true, url:'gridedit.jsp',reloadAfterSubmit:true,

  onclickSubmit: function (options, rowid) {
      var rowData = jQuery(this).jqGrid('getRowData', rowid);
      var params ={amount:rowData.amount,account:rowData.account.replace(/-/g,"")};

      return params;
  },

  afterSubmit: function () {
      $(this).jqGrid('setGridParam', {datatype:'json'});
      return [true,'']; 
  }
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
AbtPst
  • 7,778
  • 17
  • 91
  • 172

1 Answers1

3

If you use multiselect: true option the second parameter of onclickSubmit of delete option will be comma separated list of ids, which will be deleting instead of just one rowid. So you have to modify your code of onclickSubmit. The direct usage of jQuery(this).jqGrid('getRowData', rowid) will be wrong. You have to make var rowids = rowid.split(",") and then iterate (with for-loop for example) over the array of rowids. You can use getRowData with rowids[i] as parameter. You have to return array of items like params instead of one object.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • if I am using a custom button, how can I get those IDs? – will824 Jan 17 '14 at 00:15
  • @will824: I'm not sure why you need the id of the custom button. The custom button can have `class` with your custom class. So if you can find `` (the row) by rowid and then search for an element with the custom class. Alternatively if you have the custom button (inside of `click` event handler for example) you can use `.closest(".jqgrow").attr("id")` to find the rowid. In the way you can identify the row in which the button was clicked. – Oleg Jan 17 '14 at 00:58
  • @will824: If you mean the custom button in navigator bar, then you can just specify `id` parameter in [navButtonAdd](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:custom_buttons#definition) call. – Oleg Jan 17 '14 at 01:00
  • actually the issue I was having was not being able to retrieve the selected ids with the selectarrr call. It was because although the checkboxes were checked we had a beforeSelect function that would not allow the row to become selectable, so the array of the ids was empty. – will824 Jan 22 '14 at 21:10
  • @will824: Probably it would be better that you describe your problem in details in new question. – Oleg Jan 23 '14 at 08:15
  • @Oleg, I implemented everything in the way you proposed but still can't gain multiple deletion. My short snippet is here: http://stackoverflow.com/q/29827453/1844996 . Any help would be greatly appreciated. Thanks. – Filip Apr 24 '15 at 08:20
  • @Filip: [The post](http://stackoverflow.com/q/29827453/1844996) describes **another problem**. One don't want to send one HTTP POST with ids of all rows which one need to delete in the database. Instead of that one want to **replace** one Ajax request to the list of separate HTTP DELETE requests: one request for one id. About your problem: it's not enough to write "my program looks this one". The program with the bug and the program where the bug is fixed looks typically very close. So one have to have frequently **the exact demo which reproduce the problem** to find the reason of the problem. – Oleg Apr 24 '15 at 08:33