jqGrid setSelect function with parametrized query(jqGrid setSelect 函数与参数化查询)
问题描述
我正在使用 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
以上都没有奏效:
if(isset ($_REQUEST["tempid"]))
$rowid = jqGridUtils::Strip($_REQUEST["tempid"]);
else
$rowid = "";
推荐答案
如果我正确理解您的问题,请使用 editoptions 和 dataUrl.您想要具有附加参数 tempid 的 URL,其值应该是当前选定行的 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-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 选项,可用于修改使用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 函数与参数化查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:jqGrid setSelect 函数与参数化查询
基础教程推荐
- php中的PDF导出 2022-01-01
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
- Web 服务器如何处理请求? 2021-01-01
- 将变量从树枝传递给 js 2022-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
- php 7.4 在写入变量中的 Twig 问题 2022-01-01
- php中的foreach复选框POST 2021-01-01
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
