【问题标题】:jqGrid setSelect function with parametrized queryjqGrid 使用参数化查询设置 Select 函数
【发布时间】:2011-11-09 10:48:51
【问题描述】:

我正在使用 jqGrid,在编辑/添加功能上我想在这些字段之一中有一个下拉列表。

如果我像这样使用 setSelect 函数,这将起作用:

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

如何将参数传递给我的查询?我试过这些:

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 = "";

【问题讨论】:

标签: php jquery parameters jqgrid


【解决方案1】:

如果我正确理解您的问题,您可以使用 editoptionsdataUrl。您希望 URL 具有附加参数 tempid,其值应为当前选定行的 rowid。

根据您的问题的语法,我想您使用了来自trirand.net 的一些商业 jqGrid for PHP 产品。在这种情况下,您应该使用标签 [jqgrid-php]。 jqGrid 是纯 JavaScript 开源产品。所以我回答了如何在 JavaScript 中添加 dataUrl 参数。

jqGrid 具有ajaxSelectOptions 选项,可用于修改使用dataUrl 的调用的jQuery.ajax 选项。您可以执行以下操作

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.ajaxdata 参数包含方法而不是属性,则每次对应的jQuery.ajax 调用都会调用该方法。我在the answer 中使用了相同的技巧。

【讨论】:

  • tempid是master grid的主键,我发给detail grid,可以得到detail grid中tempid的值。我的问题是我不知道如何使用 setSelect 函数来传递带参数的查询
  • @Grace:我看不出有什么不同。您可以在详细信息网格中使用myMasterGrid.jqGrid('getGridParam', 'selrow');。或者,您可以将主网格的当前选定行的 id 保存在变量中(如masterRowId)。您可以在主网格的onSelectRow 事件中执行此操作。然后你可以使用tempid: function () { return masterRowId; }
  • @Grace:可能你在错误的地方使用了ajaxSelectOptions。我修改了一些答案,以更清楚地表明您应该将ajaxSelectOptions 添加到您使用的其他 jqGrid 选项中。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-12
  • 1970-01-01
  • 1970-01-01
  • 2022-08-02
  • 1970-01-01
相关资源
最近更新 更多