Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
304 views
in Technique[技术] by (71.8m points)

php - jqGrid setSelect function with parametrized query

I'm using jqGrid, on 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 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 = "";
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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 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');
            }
        }
    }
});

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...