JqGrid setSelect function with parameterized query

I am using jqGrid in the 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 follows:

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

How to pass parameters to my request? I tried:

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 "SELECT DISTINCT name,name as TestingName FROM template where tempid = ". $rowid

none of the above actions were:

 if(isset ($_REQUEST["tempid"])) $rowid = jqGridUtils::Strip($_REQUEST["tempid"]); else $rowid = ""; 
+6
source share
1 answer

If I understand your question correctly, you are using editoptions with dataUrl . You want to have a URL with an optional tempid parameter whose value should be the rowid of the currently selected row.

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

jqGrid has an ajaxSelectOptions parameter that can be used to change jQuery.ajax options for a call using dataUrl . You can do the 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 jQuery.ajax contains a method instead of a property, the method will be called each time the corresponding jQuery.ajax call. I used the same trick in the answer .

+4
source

Source: https://habr.com/ru/post/901105/


All Articles