Forum
00:13
05/09/2014
I am using the search toolbar and I have all of the features working except I cannot figure out how to pass the values from one dropdown box to the server page to narrow the returned items in the dropdown list. When something has been selected for field I want it to narrow down the list of well names in the other dropdown box to only those available in that field.
I was hoping the post option would be active and pass the field automatically, but of course it could not be that simple. I'm guessing this needs tied to an event but have not been be able to find any examples.
Â
     // <![CDATA[       jQuery(document).ready(function()       { jQuery("#grid").jqGrid({             url: "getinfo.php",             datatype: "json",             mtype: 'POST',             autowidth: true,             height: 330,             colNames: ["Name", "Num", "Field", "Pad", "API", "Legal", "County, State",                "Lease", "Unit CA PA", "Status", "Updated", "Wildlife Stips", "Notes"],             colModel: [                { name: "well_name", width: 48,sortable: true, search:true, stype:'select', searchoptions: {dataUrl:'selectwell.php'}},                { name: "well_num", width: 18,sortable: true, search:true, stype:'text'},                { name: "field", width: 48,sortable: true, search:true, stype:'select', stype: 'select', searchoptions: {dataUrl:'selectfield.php'}},                { name: "pad", width: 36,sortable: true, stype:'text'},                ...             ],             rowNum:10,             rowList:[10,25,50,10000],             pager : '#pager',             sortname: 'field',             viewrecords: true,             rownumbers: true,             gridview: true,             sortorder: "asc",             caption:"Master Well List Maintenance"          });          jQuery("#grid").jqGrid('navGrid','#pager',          {             view: true,             del: false,             add: true,             edit: true,             search: false,             refresh: true          },          { /*prmEdit*/ },          { /*prmAdd*/ },          { /*prmDel*/ } ,          {             /*prmSearch*/             multipleSearch:true          },          { /*prmView*/ }          );          $('#grid').jqGrid('filterToolbar', { searchOnEnter: true, enableClear: true });          $('#grid').jqGrid('navButtonAdd', '#pager', {                caption: "",                title: "Toggle Search Toolbar",                buttonicon: 'ui-icon-search',                onClickButton: function () {                    this.toggleToolbar();                    if ($.isFunction(this.p._complete)) {                        if ($('.ui-search-toolbar', this.grid.hDiv).is(':visible'))                   {                                                 $('.ui-search-toolbar', this.grid.fhDiv).show();                        } else {                            $('.ui-search-toolbar', this.grid.fhDiv).hide();                        }                        this.p._complete.call(this);                        fixPositionsOfFrozenDivs.call(this);                    }                }            });          $('.ui-search-toolbar').hide();       });        // ]]>
Â
Server code...
<!--?php
include("../Includes/aedclass.php"); $nconn = new WorkData(); $conn = new PDO ($nconn->DB_DSN,$nconn->DB_USER,$nconn->DB_PASSWORD); $field = $_POST['field']; if (strlen($field)>0) { $sql = "SELECT field FROM master_well_list WHERE field='$field' GROUP BY field ORDER BY field asc;"; } else { $sql = "SELECT field FROM master_well_list GROUP BY field ORDER BY field asc;"; } $stmt = $conn->prepare($sql); $stmt->execute(); $response =''; $response .= ' '; while($row = $stmt->fetch(PDO::FETCH_NUM)) { Â Â Â $response .= ' '.$row[0].' '; } $response .= ''; echo $response; ?>
12:50
Moderators
30/10/2007
Hello,
Â
As far as I understand you try to make depened dropdown in search toolbar.
Using dataUrl is way to build the selects only once when the search toolbar is created.
I think you will need to bind a change event to the first dropdown on which when the values is changed to will the second with the needed values.
You can use dataEvents option to do this - see the docs.
To grab the second select element you should know that the id of this element is a combination of gs_ plus the column name.
Â
Kind Regards
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
Most Users Ever Online: 715
Currently Online:
46 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66