0

I am using inlineNav (successfully due to assistance here!).

Now using dataUrl in a select statement, I do not understand the behavior.

The select options are not loaded when the grid is loaded. The select HTML request is not made until either edit or add a record is pressed.

Can I get it to load as soon as the grid is loaded?

$("#navgrid").jqGrid({
    sortable: true,
    rownumbers: true,
    url: 'cms.dbw?action=ajaxgrid&sessionid=3d70a780-d6ec-102f-bd56-0015171f0bcc&subaction=jq&tableid=carepln',
    editurl: 'cms.dbw',
    datatype: 'json',
    mtype: 'GET',
    pager: '#navgrid_bottompager',
    rowNum: 10,
    rowList: [10,50,100],
    width: 750,
    height: '100%',
    shrinkToFit: false,
    toolbar: [false,'top'],
    sortname: 'id',
    sortorder: 'asc',
    viewrecords: true,
    gridview: true,
    altRows: false,
    toppager: true,
    caption: 'Care Plan Detail',
    colNames: ['ID','Act','Resident Code','Care Code'],
    colModel: [
        {name:'id',index:'id',width:50,align:'center',search:false,key:true,hidden:true},
        {name:'active',width:30,align:'center',editable:true,edittype:'checkbox',editoptions: {value:'Y:N'},formatoptions:{disabled:false,value:"Y:N"}},
        {name:'resid',align:'left',editable:true,width:70},
        {name:'classid',align:'left',editable:true,edittype: 'select',editoptions: { dataUrl: 'cms.dbw?action=ajaxgrid&sessionid=3d70a780-d6ec-102f-bd56-0015171f0bcc&subaction=jqsubtable&tableid=careserv&field1=classid&field2=description'} ,width:70}
    ]
}); 

{"page":1,"records":4024,"total":403,"rows":[{"id":"1","cell":["1","Y","100243","22020"]},{"id":"2","cell":["2","Y","100220","22020"]},{"id":"3","cell":["3","Y","100193","22020"]},{"id":"4","cell":["4","Y","100082","22020"]},{"id":"5","cell":["5","Y","100068","22020"]},{"id":"6","cell":["6","Y","100241","22020"]},{"id":"7","cell":["7","Y","100215","22020"]},{"id":"8","cell":["8","Y","100059","22020"]},{"id":"9","cell":["9","Y","100240","22020"]},{"id":"10","cell":["10","Y","100009","22020"]}]}

The dataUrl does not resolve until the edit is started. And does not display after the edit.

Luís Cruz
  • 14,780
  • 16
  • 68
  • 100
Greg Neid
  • 23
  • 1
  • 8

2 Answers2

0

I see no disadvantage from the loaded of dataUrl at the start of editing. On the contrary I see such behavior as the advantage. First of all one should not load optional data. It's better to load the data on demand. Second advantage is that you get the current data from dataUrl. On start of editing the current data from dataUrl will be loaded. So if the data will be changed on the server you can have different values on every row editing.

If you need load the data only once you can don't use dataUrl at all. Instead of that you can make separate Ajax call to set editoptions.value with respect of setGridParam.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • I understand the advantages that you have listed, and I believe that jqGrid is an exceptional tool. – Greg Neid Apr 12 '12 at 19:32
  • I understand the advantages that you have listed, and I believe that jqGrid is an exceptional tool. What I hoped it would do is act like a true select box in the grid itself and by ajax bring in the options from the server -- and it does as soon as I edit or add. But, the display of the as well. – Greg Neid Apr 12 '12 at 19:39
  • @GregNeid: Sorry, do you want to use selects in [inline editing](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:inline_editing)? In the case you do can use `dataUrl`. What is the current problem which you has? – Oleg Apr 12 '12 at 19:47
  • The dataUrl works very well for editing, but it does not display as the – Greg Neid Apr 12 '12 at 21:09
  • @GregNeid: Probably it's misunderstanding. Why the – Oleg Apr 12 '12 at 21:14
  • Value works as I described, displaying in both display and edit mode. DataUrl only displays correctly in eit or add mode. – Greg Neid Apr 12 '12 at 23:20
  • @GregNeid: There are no "display" mode. You should append your question with the code which you use to clear what you do. – Oleg Apr 12 '12 at 23:36
  • colNames:['Resident Code','Care Code'], colModel:[{name:'resid',align:'left',width:70,editrules:{ }} ,{name:'classid',align:'left',editable:true,edittype: 'select',formatter:'select',editoptions: { dataUrl: 'cms.dbw?action=ajaxgrid&sessionid=417312ea-d6de-102f-bd56-0015171f0bcc&subaction=jqsubtable&tableid=careserv&field1=classid&field2=description'} ,width:150,editrules:{ }} ] }); Field classid remains blank (inspector shows   in ) until editor is launched. At that time, get is issued to the server and the – Greg Neid Apr 13 '12 at 18:56
  • @GregNeid: You should click on "edit" link at the bottom of the question (see [here](http://stackoverflow.com/faq#howtoask)) and include the full code of jqGrid. See [here](http://meta.stackexchange.com/a/22189/147495) how to format the code. Additionally you should include JSON data from the server response (`url` parameter) and the JSON response from the `dataUrl`. You can use [Fiddler](http://www.fiddler2.com/fiddler2/), [Firebug](http://getfirebug.com/) or [Developer Tools of IE](http://msdn.microsoft.com/en-us/library/gg130952(v=vs.85).aspx) or Chrome to catch HTTP traffic. – Oleg Apr 13 '12 at 19:17
0

I have the same issue - I have a foreign key in my data, and I'd like the grid to show some understandable value for this column, rather than some random key that the user will not know. Like you, I've used dataUrl to get the options, and would like to use formatter:'select' to have it display these values even when not editing the row. The problem is that this ajax request only happens when the row is edited, so it doesn't know the values until editing happens. The only solution I've found is just to do some manual ajax loading of these values before setting up the grid, and using these values to set editoptions: {value: ... } as you did for one of the other columns. This is the only way that the grid formatter can know these values before editing occurs.

This answer provides an example of loading the options before the gird, but leaves out the formatter:'select' part - here's a link to the documentation about that.

Community
  • 1
  • 1
  • @ZacharyOlsen: The 'password' does not resolve before editing either. It displays the password until you edit it, then it becomes ************. – Greg Neid Apr 15 '12 at 11:02
  • That's a little frustrating - I would have assumed if there were an edittype for it, there would be a formatter type for it. Found this discussion that extends it to handle this case as a work around: http://www.trirand.com/blog/?page_id=393/help/how-to-hide-password-characters-in-column-formatterpassword-is-ignored/ – Zachary Olson Apr 15 '12 at 17:59