带参数化查询的jqGrid setSelect函数 [英] jqGrid setSelect function with parametrized query
问题描述
我在编辑/添加功能上使用的是jqGrid,我想在这些字段之一中创建一个下拉列表.
I'm using jqGrid, on edit/add function I want to have a drop down list in one of these fields.
如果我按以下方式使用setSelect函数,这将起作用:
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 = "";
推荐答案
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.
根据您问题的语法,我想您使用 trirand.net 的一些商业jqGrid for PHP产品>.在这种情况下,您应该使用标签[jqgrid-php]. jqGrid是纯JavaScript开源产品.因此,我回答了如何在JavaScript中添加dataUrl
参数.
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具有 ajaxSelectOptions 选项,可用于 modify 使用dataUrl
的呼叫的jQuery.ajax
选项.您可以执行以下操作
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');
}
}
}
});
如果 jQuery.ajax 的data
参数包含方法而不是属性,每次相应的jQuery.ajax
调用都将调用该方法.我在
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.
这篇关于带参数化查询的jqGrid setSelect函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!