0

i had a script like this

<script type="text/javascript">
var gridimgpath = 'themes/basic/images'; 
//alert($("jqContextMenu"));
jQuery("#VWWMENU").jqGrid(
    {
     url:'loadstatic.php?q=2&t=CORE_VW_WMENUS',
     datatype: "json", 
     mtype: "POST", 
     colNames:['Id', 'Module'],
     colModel:
     [
     {
     name:'id',
     index:'id',
     width:7,
     editable:true,
     edittype:'text',
     editrules:{required:true},
     editoptions:{maxlength:10, size:10},
     formoptions:{rowpos:2, elmprefix:' '},
     key:true
     },
     {
     name:'modulename',
     index:'modulename',
     width:15,
     editable:true,
     edittype:'select',
     editrules:{required:true},
     editoptions:{maxlength:10, size:0, dataUrl:'combopub.php?t=MODULE'},
     formoptions:{rowpos:1, elmprefix:' '}
     }
...
</script>

the 'modulename' form is a combobox which taken its data from a table named 'module'. in this 'module' table there is a column named "fromid" and "toid". now how can i get these two values to be the range for the 'id' form? so when i input a value to form 'id' and then i submit it, it will show a message about id that i entered is out of range. i also don't know how to make the message that to appear when this error happened. so would you guys please help me on this?

i am still a total noob about this javascript or jquery kind of thing, so your help would be much appreciated.

i hope this would help to make it clearer of what i mean. here is table module:table_module. from left to right (exclude column covered with the red line) idmodule, namemodule, idchildfrom, idchildto. and the module name that shown on the screen is actually a concate of idmodule and namemodule

now if you pick 2 from modulename combobox like this combobox_1 then you should get the range id from 201-400. and that means if you input a value of 300 into id and you press submit button, there would be an error message appear telling you that your input is more is out of range.

i hope this explanation can help you to understand more of what i actually wants to do

R_A_P
  • 5
  • 1
  • 3

1 Answers1

2

If I understand you correctly you can use relatively new feature (it exist starting with jqGrid 4.4.2) implemented based on my suggestion. It allows to use postData defined as function:

{
    name: "modulename",
    width: 15,
    editable: true,
    edittype: "select",
    editrules: {required: true},
    editoptions: {
        maxlength: 10,
        size: 0,
        dataUrl: "combopub.php",
        postData: function (rowid) {
            return { id: rowid, t: "MODULE" };
        }
    },
    formoptions: {rowpos: 1, elmprefix: " "}
}

See the answer and the pull request for more details.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • it seems that i used jqgrid version 4.3.2 so i don't think it will works. besides i don't really understand with what you mean about rowid. is it rowid on table "module"? is it the rowid that we take to become the range for form 'id'? then how do the other form know whether it's a maxvalue or minvalue? – R_A_P Apr 29 '13 at 09:08
  • @R_A_P: request to `dataUrl` will be sent at the start editing of the row. In case of usage HTTP GET the `postData` will be appended to the URL. The callback `postData` allows you to specify which additional information you want to have on the server. If the user start editing of the row with `id=123` then `postData` will be called with `rowid` parameter equal to 123. `postData` returns `{ id: rowid, t: "MODULE" }` so the `combopub.php` will be appended with `?id=123&t=MODULE`. So **the server can returns ` – Oleg Apr 29 '13 at 09:17
  • @R_A_P: Think about setting caching header on the server side or use the options described [here](http://stackoverflow.com/a/7422410/315935). If you *really have to use old version of jqGrid* you can use `ajaxSelectOptions.data` with properties defined as functions see [here](http://stackoverflow.com/a/13525607/315935). – Oleg Apr 29 '13 at 09:22
  • the post data part, as i thought, didn't work. and i don't really understand with your post about ajaxSelectOptions. could you explain more the use of that ajaxselectoptions in my case? – R_A_P Apr 30 '13 at 08:15
  • @R_A_P: If you specify `dataUrl` property for `editoptions` then jqGrid make jQuery.ajax call to get the list of options dynamically from the server. The `ajaxSelectOptions` can be used to modify parameters of the jQuery.ajax request. Old versions of jqGrid don't use `data` parameter (see [here](https://github.com/tonytomov/jqGrid/blob/v4.3.2/js/grid.common.js#L345-L385)) so you can specify it inside of `ajaxSelectOptions`. `data` parameter should be better an object. You can use properties of `data` as functions which will be called immediately before the Ajax request. – Oleg May 10 '13 at 13:47
  • @R_A_P: I hope that, after the information from the last comment, you will understand [the answer](http://stackoverflow.com/a/13525607/315935). You wrote "the post data part, as i thought, didn't work". I interpret it that you make some attempt, but it failed. I can't help to if you don't post *the code of the attempt* so that I could show you where you made the error. – Oleg May 10 '13 at 13:51