0

I need to have the currently selected row id in order to build a JSON string that will be passed to a php script in order to create a select, so I enclosed the script reference and code in a function.

However, doing so creates a NetworkError: 403 Forbidden error.

Here is the code segment:

editoptions:{dataUrl:function(){
var row_id   = $('#tab3-grid').getGridParam('selrow');
var jsondata = JSON.stringify({"cu.STID": $('#tab3-grid').jqGrid('getCell', row_id, 'cu.STID'),
                               "wv.SVID": $('#tab3-grid').jqGrid('getCell', row_id, 'wv.SVID')});

return 'php/items-se-script.php?data='+jsondata;
},

Does anyone know whats going on?

UPDATE:

{name:'it.PRID', index:'it.PRID', hidden: true, editable:true,  edittype:'select',
editoptions:{dataUrl:'php/items-se-script.php', defaultValue:'26', dataEvents:[{type:'change',fn:function(e){$('input#ip\\.Item').val($('option:selected', this).text());}}]},
formoptions:{label:'Item', elmprefix:'* '},
editrules:{edithidden:true, required:true}},

{name:'ip.Item', index:'ip.Item', hidden: true, sortable: true, editable:false, edittype:'text', editoptions:{readonly:true,size:20}, formoptions:{rowpos: 50, label:'Item'}, editrules:{required:true}}

],

ajaxSelectOptions: {
   type:'POST',
   data: {
      data: function () {
         var row_id = $('#tab3-grid').getGridParam('selrow');
         return JSON.stringify({
            "cu.STID": $('#tab3-grid').jqGrid('getCell', row_id, 'cu.STID'),
            "wv.SVID": $('#tab3-grid').jqGrid('getCell', row_id, 'wv.SVID')
         });
      }
   }
},

url:    'php/workordertab-script.php',
editurl:'php/workordertab-script.php',
Matt Hulse
  • 5,496
  • 4
  • 29
  • 37
Nelson M
  • 181
  • 4
  • 13

1 Answers1

1

The property dataUrl can't be a function. If you need to send any additional information to the server during building of select you can use ajaxSelectOptions option like I described as here. In your case it will be about the following:

var $myGrid = $('#tab3-grid');
$myGrid.jqGrid({
    // ... here all you current parameters which includes
    //     editoptions: { dataUrl: 'php/items-se-script.php' }
    // for the corresponding column in colModel
    ajaxSelectOptions: {
        data: { // "data" here is jQuery.ajax parameter 
            data: function () { // "data" here is the name of you custom parameter
                var row_id = $myGrid.getGridParam('selrow');
                return JSON.stringify({
                    "cu.STID": $myGrid.jqGrid('getCell', row_id, 'cu.STID'),
                    "wv.SVID": $myGrid.jqGrid('getCell', row_id, 'wv.SVID')
                });
            }
        }
    }
});
Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • @OIeg, it worked - thanks! I realized that the ajaxSelectOptions option fires for all select dataUrl's in the grid. Is there a way to have ajaxSelectOptions fire for only one specific select dataUrl in the grid? – Nelson M Nov 17 '11 at 06:18
  • @NelsonM: No you can't make individual `ajaxSelectOptions` (see [here](https://github.com/tonytomov/jqGrid/blob/v4.2.0/js/grid.common.js#L345) and [here](https://github.com/tonytomov/jqGrid/blob/v4.2.0/js/grid.inlinedit.js#L60) or [here](https://github.com/tonytomov/jqGrid/blob/v4.2.0/js/grid.formedit.js#L425). You can have different URLs for different columns of grid, but one general `ajaxSelectOptions` option. – Oleg Nov 17 '11 at 06:41
  • @OIeg, In order to create the right select list in this situation i have to know if the form is "add" or "edit". Other than defining a editData: in navgrid for edit and add, is there a jqgrid global variable that identifies whether the add or edit navigation button was pressed? – Nelson M Nov 17 '11 at 07:13
  • @NelsonM: You can set any variable in the [onInitializeForm](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:form_editing#events) method which can be different for Add and Edit forms. The variable mast be not global, but be in scope of the function where you want use it. Moreover you can even change the value of `ajaxSelectOptions` inside of both `onInitializeForm`. In the way you can have different `ajaxSelectOptions` for Add and Edit form and can have even different settings for different rows or grid, but you can't set different `ajaxSelectOptions` for different columns. – Oleg Nov 17 '11 at 07:24
  • @OIeg, ok... thanks for being so helpful. I'm trying to learn and program in jqgrid, jquery and javascript all at the same time. – Nelson M Nov 17 '11 at 07:28
  • @NelsonM: You are welcome! I hope you understand that I mean `var inEdit = false; $('#list').jqGrid('navGrid', 'pager', {}, {/*edit options*/onInitializeForm: function() {inEdit = true;}}, {/*add options*/onInitializeForm: function() {inEdit = true;}}` and you test `inEdit` variable inside of `data: function () {/*... test inEdit here...*/}` – Oleg Nov 17 '11 at 07:33