2

I am triggering jqgrid reload on button click and also resetting the page value to '1' for my pagination to work correctly. But jqgrid submits the value present in the grid(if on 2nd page it sends a value of '2) and it also sends some additional parameters which were part of previous search. How can I avoid that please?

$('#delete').click(function() {
    var rowIds = msgGrid.jqGrid('getGridParam','selarrrow');
    $('#grid').setGridParam({url:'delete.html?rowIds=' + rowIds,
     page: '1'
    }); 
    $('#userGrid').trigger("reloadGrid");  
});

jQuery(function() {
  jQuery("#grid").jqGrid({
    url:'page.html',
    datatype: 'json',
    mtype: 'POST',
        .....  
    postData: { 
       totalRecords: function() { return $('#grid').getGridParam("records"); } 
        },
    rowNum: 25,
        .....
  });
});

When the grid is first loaded my url is page.html, but when user selects some rows and clicks delete, I am changing the url to delete.html with selected rows. The delete functionality deletes the selected rows and sends the latest data back to grid. Now if I click on refresh, it is still going to delete.html as my url is not changed. Also if user selects few rows before refresh, the selected rows data get deleted as the url is not changed...

varaprakash
  • 487
  • 4
  • 12
  • 30

1 Answers1

2

You should change the page directly with page: 1 instead of postData: { page: '1' } (see here) or just use parameter [{page:1}] of reloadGrid (see here).

You don't wrote enough information about the sending some additional parameters which were part of previous search. If you use loadonce:true parameter then you have to reset datatype parameter to its original value (see here or here).

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Oleg: thanks for the solution, I am sending page value as '1' using setGridParam(), that solved my problem. Regarding sending previous search data, for example on button click if change the grid URL to /deleteData and after some time if I click on refresh grid, it is going to the changed URL instead of grid URL which is /getData. I think I need to reset the URL value after loadComplete(). Just wanted to know which is the best place to do it. Please suggest me. Thanks! – varaprakash Jan 19 '12 at 19:51
  • @varaprakash: You are welcome! It's difficult for me to answer on your last questions because you don't posted the HTML code of the form `#form` and don't post any examples of `$('#form').serialize()`. In the most cases you don't need change the `url` at all. You can use some custom properties of `postData` instead. The URL like `/deleteData` sound especially strange. Probably you should use `editdata` or `url` parameters of the editing. I don't know which editing mode you use. – Oleg Jan 19 '12 at 20:21
  • Oleg: thank you. I updated my question with details. I am not using editData functionality, it is just a button outside the grid and would like to have it that way. – varaprakash Jan 19 '12 at 21:01
  • @varaprakash: Sorry, but I still don't full understand what you do. Do you use form editing? The method [delGridRow](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:form_editing#delgridrow) can be used to send POST (or other HTTP command) request to the server with the id of the row which should be deleted. Then `reloadGrid` will be done per default and the data in the grid will refreshed. Typically one uses [navGrid](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:navigator) to add Delete button in the pager part of the grid. – Oleg Jan 19 '12 at 21:11
  • Oleg: Thanks. As I mentioned I am not using navGrid functionality to delete or edit. I have some custom functionality like acknowledging selected rows, deleting, forwarding which I thought would be better to have those buttons outside the grid. I got a solution to fix this issue. Instead of default refresh icon, I am using a navButtonAdd for refresh and on click of that I am changing url back to page.html... – varaprakash Jan 19 '12 at 21:16
  • @varaprakash: You can call any from form editing method like `delGridRow` from the outside too. If you look at [the code](https://github.com/tonytomov/jqGrid/blob/v4.3.1/js/grid.formedit.js#L1430-1641) of the method to see what it do. It displays additional confirmation dialog. In any way even if you post the data manually per `jQuery.ajax` (like $.ajax(url:'delete.html', type: 'POST', {data: {'rowIds': rowIds}, success: function () {$("#grid").trigger('reloadGrid');} })). I don't see any need to change the URL of the grid to `delete.html` – Oleg Jan 19 '12 at 21:27