6

I'm using jqGrid, on edit/add function I want to have a drop down list in one of these fields.

This works if i use the setSelect function as this:

$grid->setSelect("title", "SELECT DISTINCT name,name as TestingName FROM template", true, true, false, array(""=>"All"));

How can I pass parameters to my query? I tried these:

1-"SELECT DISTINCT name,name as TestingName FROM template where tempid = ?"

2- "SELECT DISTINCT name,name as TestingName FROM template where tempid = $rowid"

3-"SELECT DISTINCT name,name as TestingName FROM template where tempid = ". $rowid

none of the above worked while having:

if(isset ($_REQUEST["tempid"]))
    $rowid = jqGridUtils::Strip($_REQUEST["tempid"]);
else
    $rowid = "";
Grace
  • 1,265
  • 21
  • 47
  • i can't find any documentation about the `->setSelect` method of the jqgrid php class on http://www.trirand.com/blog/phpjqgrid/docs/jqGrid/jqGrid.html#sec-method-summary can you provide some more information? – Manuel van Rijn Nov 09 '11 at 15:17
  • http://www.trirand.net/documentation/php/index.htm -> section tutorials->drop downs – Grace Nov 09 '11 at 15:20

1 Answers1

4

If I correct understand your question you use editoptions with dataUrl. You want to have the URL which has additional parameter tempid which value should be the rowid of the current selected row.

From the syntax of your question I suppose that you use some commercial jqGrid for PHP product from trirand.net. In the case you should use tag [jqgrid-php]. jqGrid is pure JavaScript open source product. So I answer how you can add dataUrl parameter in JavaScript.

jqGrid has ajaxSelectOptions option which can be used to modify the jQuery.ajax options of the call which use dataUrl. You can do following

var myGrid = $("#list");

myGrid.jqGrid({
    // all your current parameters of jqGrid and then the following
    ajaxSelectOptions: {
        data: {
            tempid: function () {
                return myGrid.jqGrid('getGridParam', 'selrow');
            }
        }
    }
});

If the data parameter of jQuery.ajax contain a method instead of a property the method will be called every time of the corresponding jQuery.ajax call. I used the same trick in the answer.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • the tempid is the primary key of the master grid, im sending it the detail grid, and i can get the value of the tempid in the detail grid. my problem is that i don't know how to use the setSelect function to pass query with parameter – Grace Nov 09 '11 at 15:36
  • @Grace: I see no difference. You can just `myMasterGrid.jqGrid('getGridParam', 'selrow');` in the detail grid. Alternatively you can save the id of the current selected row of the master grid in a variable (like `masterRowId`). You can do this inside the `onSelectRow` event of the master grid. Then you can use `tempid: function () { return masterRowId; }` – Oleg Nov 09 '11 at 15:43
  • @Grace: Probably you use `ajaxSelectOptions` in the wrong place. I modified a little my answer to show more clear that you should add `ajaxSelectOptions` to other jqGrid options which you use. – Oleg Nov 09 '11 at 16:48