0

I'm going to simplify this question.

I have a jqgrid instance which posts an array of ids to the server. I would like the pass in a new list when an event is triggered. Instead of overwriting the old list, jqgrid will add to it. How can i set the post parameters to create a new list each time I reload the grid.

This is the code to reload the grid with new post data

  $('#gridConfirm').jqGrid('setGridParam',{postData:{'deviceIDs':$("#device").val()}});
  $('#gridConfirm').trigger('reloadGrid');

I've confirmed that $("#device").val() returns a list of id's in the form "5,6,7,8"; So i'm expecting this list to be posted to the server.

Instead, its posting "5,6,7,8" plus the previous list. so if the previous list was "1,2,3,4". It's posting "5,6,7,8,1,2,3,4"

How can i clear the previous posted list when reloading the grid?

*edit* On slight correction, when i change my postdata list. It does not append it overwrites, but it keeps the length of the list.

so if my original list was 1,2,3,4,5 and i selected 6,7 my new list is 6,7,3,4,5

I'm thinking this is a bug in the grid.

Darren Cato
  • 1,382
  • 16
  • 22
  • The name `'deviceIDs[]'` seems me strange. Do you want to send additional parameter in the form `deviceIDs[]=foobar` or you need to have `deviceIDs=["foo","bar"]`? Which data returns `$("#device").val()`? – Oleg Aug 08 '11 at 17:18
  • well deviceIDs[] stores the values in array form. That way i can pass multiple related values in one variable. So yes im trying to do deviceIDs = ["foo", "bar"]. This works fine on the initial load. but if i need to relood the grid and pass, DeviceIDs = ["new", "vals"]. I end up with ["foo","bar","new","vals"] – Darren Cato Aug 08 '11 at 18:32
  • I have to repeat: Which data returns `$("#device").val()`? Is it `new, vals`, `"new", "vals"` or in another format? How the jqGrid are defined? Are the data send from the server in the JSON format? Do you want to send data also in JSON format?... – Oleg Aug 08 '11 at 18:59
  • device.val() is a drop down list of ids. its in the form new, vals. I'll update the question to show how its posted in firebug – Darren Cato Aug 08 '11 at 19:28
  • If you use in the ` – Oleg Aug 08 '11 at 19:36
  • Could you add the definition of the `$('#gridConfirm').jqGrid` and the HTML code which defines all the used HTML elements "#popGrid", "#device" and '#gridConfirm'? – Oleg Aug 08 '11 at 22:25
  • I've added the full definition of $('#gridConfirm').jqGrid. #popGrid" is just a button, #device is a multiselect list. Thanks for you continued help – Darren Cato Aug 10 '11 at 19:54
  • any new info on this, still stuck. – Darren Cato Aug 26 '11 at 16:58
  • You don't posted enough information to allow other to reproduce your problem. Instead of posting raw JSON data which you can see in Firebug or Fiddler you posted some table having strings like `deviceIDs[] 20856`. So it is not clear in which exactly format the data returned from the server. See [here](http://stackoverflow.com/questions/7190863/jqgrid-filtertoolbar-not-working/) for clear described data. Moreover I asked you to post your HTML markup, because you code contains *undefined* objects like `'#gridConfirm'`. You answer "#popGrid" is just a button..." help not **to reproduce** it. – Oleg Aug 26 '11 at 17:08
  • Moreover your code which you posted contain many other external calls like `$(".popup").colorbox(...` or `$("[title]").easyTooltip();`. It is really important? You should clear describe your problem without unneeded details. Only in the case other people could understand your problem, reproduce it and then probably provide a solution of your problem. – Oleg Aug 26 '11 at 17:11
  • you're right, i've simplified the question. – Darren Cato Aug 26 '11 at 20:33

1 Answers1

0

Now you removed all code from your question. So I wrote the demo myself which has no problem which you described. You can look at the source and compare with your version to see where you have a problem. In any way I would recommend to use postData having functions as properties (see here).

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Ok Thanks for the demo but i dont think you get understand my question. I tried using a function in postdata, but it did not help. The problem is that when i select the new list and try to submit new postdata info, the old post data info does not clear. I used to think that the new data was appended to the old data, however i now realize that it overwrites the list. .... i've edited the question to explain – Darren Cato Sep 01 '11 at 19:06
  • @Shaded2: The new data can be appended only if you fill it in the wrong way. If you would use [Fiddler](http://www.fiddler2.com/fiddler2/) of [Firebug](http://getfirebug.com/) you will see **which data** will be included in the request to the server by my demo. If you select some elements in the select box and click "Reload" button in the grid toolbar (`.trigger('reloadGrid')` will be called) you will see that **only values of selected items** will be send to the server. So all works not like you as described. So it is not jqGrid problem. The bug should be in your code which you not posted. – Oleg Sep 01 '11 at 19:38
  • Oleg thank you very much for you help, especially with creating the demo. I was able to solve the issue. In the beginning i used postData:{'deviceIDs[]':$("#device").val()} to gather all my ids. The worked well in that it sent an array of ids back to the server. It does not work well for reposting however. So I used a function to return a string of ids to post data like you suggested, and i modified my back end code to accept either a string or an array. – Darren Cato Sep 02 '11 at 18:37
  • @Shaded2: You are welcome! After the problem is solved it is easy to explain everything, but at the beginning all looks very complex and unclear. So I prefer to create small working demos. If you have a working example it helps mostly find the difference and localize the problem – Oleg Sep 02 '11 at 18:51