I need to make jqGrid to dynamically set edit & delete urls, depending not only on selected row's ID, but also on the content of other row's columns. All the examples I've found, deal with onclickSubmit which has only "id" field exposed. Any tips?
3 Answers
There is only one value for editing and deleting: 'editurl'. So you will only need to update that one. You can change the value for editurl with setGridParam, like so:
$("#jqGridTable").setGridParam('editurl', 'myNewUrl/foo');
If you want to build that URL using logic based on the contents of the currently-selected row, then do something like this:
onSelectRow: function(id){
var rowData = $("#jqGridTable").getRowData(id);
// example logic
if (rowData['col1'] == 'foo' && rowData['col2'] == 'bar')
$("#jqGridTable").setGridParam('editurl', 'myNewUrl/foo/bar');
else
$("#jqGridTable").setGridParam('editurl', 'myNewUrl/foo');
}

- 16,785
- 5
- 53
- 66
-
1+1 I agree with you. I think only that it's not **the only way**. – Oleg Dec 27 '11 at 18:50
-
I never quite wrote "the only way" is to do it this way, although it does sound almost like I said that. What I meant when I said "you will only need to update that one" was not that it was the exclusive means of accomplishing this, but rather that it was simplest way of doing so. – Jake Feasel Dec 27 '11 at 19:01
-
OK, I don't exactly repeat your words, but `editurl` is really not the only parameter which can be modified. If one uses `url` property inside of `prmEdit`, `prmAdd` or `prmDel` parameter of [navGrid](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:navigator#definition) the `editurl` will be ignored. But I don't want be too formal. I said before that the way which you suggested should work and you wrote about the usage of `getRowData` which seems was the main problem from the question. – Oleg Dec 27 '11 at 19:42
I decide to write my answer only because Jake Feasel wrote "There is only one value for editing and deleting: 'editurl'" in his answer. I think that there are many way and the best one depend on the other requirements.
In general the data sent to the server consist from tree parts
- The type of HTTP request like POST, PUT or DELETE
- The part of the URL till the '?' character
- Parameters of the URL till after the '?' character
- The body of the HTTP request
Per default jqGrid uses HTTP POST request and place the information about the id (or comma separated list of ids in case of multiselect: true
) in the body of the HTTP request. If you change the type of the HTTP request you could have to change the place of the information which you send to the server from body to the URL for example. In case of usage RESTful services on the server side one should use HTTP DELETE for delete operation and has empty body in the case.
In any way one use some callback functions (events) to fill additional information about the editing or deleting row. Inside of the callback functions one can use getRowData
or getCell
methods to get additional information for other cells of the deleting or editing row. Sometimes depend on the exact situation which one has the methods will not work. It will be in case of cell editing of inline editing if you would try to get information from the cell which contain are changed to <input>
, <select>
or other control during the editing. In the case there are other tricks which can be used as a workaround (see here for example).
One way is get change the URL inside of onSelectRow
because one delete or edit the last selected row. I would only use $(this)
instead of $("#jqGridTable")
.
Another way is to change the url
inside of onclickSubmit
(see here and here).
Both the ways I would recommend to use only if one need to change the part of the URL till the '?' character. If you need just add additional parameters to the url like paramNama=paramValue
divided by &
you can better use editData or delData parameters instead. The parameters can contains functions. See here or here.
If you need change the body of the requests you can use serializeDelData
or serializeEditData
.
So there are many ways and which is the best way depend on your other requirements.
-
I also would ordinarily use $(this) rather than $('#jqGridTable'), but without the full context I figured that would be more confusing. – Jake Feasel Dec 27 '11 at 19:05