带有参数化查询的 jqGrid setSelect 函数

jqGrid setSelect function with parametrized query(带有参数化查询的 jqGrid setSelect 函数)
本文介绍了带有参数化查询的 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.您希望 URL 具有附加参数 tempid,其值应该是当前选定行的 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 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)