Hi All
I’ve been searching the forums and the web and found examples of dependent dropdowns for the filterToolBar, but all of them seem to related to editing the grid.
I have a simple grid that has 4 columns to filter by. What I am trying to achieve is that when I choose an item from the first column’s filter dropdown, it will change the option list of the 2nd, 3rd and 4th columns option list based on the selected value from column 1. Then when a value is selected from column 2’s list, columns 3 and 4 options are updated with the selected options from columns 1 and 2, and so on.
Here’s my php code:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
require_once '/var/www/html/jqSuite460/jq-config.php'; require_once ABSPATH."php/jqGrid.php"; require_once ABSPATH."php/jqGridPdo.php"; $db = new PDO(DB_DSN.'cds',DB_USER,DB_PASSWORD); $where = "where (ipv4 != 'n/a' and ipv4 != 'N/A' and ipv4 != '')"; if (isset($_REQUEST['filters'])) { $filters = json_decode($_REQUEST['filters'],true); foreach ($filters['rules'] as $key => $val) { switch ($val['field']) { case "platform": $where = $where ." and platform = '{$val['data']}'"; break; case "location": $where = $where ." and location = '{$val['data']}'"; break; case "nec": $where = $where ." and nec = '{$val['data']}'"; break; case "voltepodp": $where = $where ." and pod = '{$val['data']}'"; break; } } } //print_r(json_decode($_REQUEST['filters'],true)); //print $where; $grid = new jqGridRender($db); $Model = array( array("name"=>"platform","label"=>"Platform","width"=>110), array("name"=>"location","label"=>"Location","width"=>140), array("name"=>"nec","label"=>"NEC","width"=>72), array("name"=>"pod","label"=>"Pod","width"=>80), array("name"=>"hostname","label"=>"Hostname","width"=>162), array("name"=>"testtime","label"=>"Last Tested","width"=>125), array("name"=>"ftp","width"=>63,"align"=>"center"), array("name"=>"ssh","width"=>63,"align"=>"center"), array("name"=>"telnet","width"=>65,"align"=>"center"), array("name"=>"rsh","width"=>63,"align"=>"center"), array("name"=>"rlogin","width"=>65,"align"=>"center") ); $sql = " select platform, location, nec, pod, hostname, testtime, ftp, ssh, telnet, rsh, rlogin from inventory1 i left join portaudit p on i.id = p.id {$where}"; $grid->SelectCommand = $sql; $grid->dataType = 'json'; $grid->setColModel($Model); $grid->setURL('auditdata.php'); $grid->setGridOptions(array( "hidegrid"=>false, "sortname"=>"testtime", "sortorder"=>"desc", "emptyrecords"=>"No Errors Found", "rowNum"=>16, "hoverrows"=>true, "rowList"=>array(15,30,60), "shrinkToFit"=>true, "height"=>"auto", "width"=>"auto", )); $grid->toolbarfilter = true; $grid->setSelect("platform","select distinct platform, platform platformList from inventory1 {$where} order by platform",false,false,true,array(""=>"All")); $grid->setSelect("location","select distinct location, location locationList from inventory1 {$where} order by location",false,false,true,array(""=>"All")); $grid->setSelect("nec","select distinct nec, nec necList from inventory1 {$where} order by nec",false,false,true,array(""=>"All")); $grid->setSelect("pod","select distinct pod, pod podList from inventory1 {$where} order by pod",false,false,true,array(""=>"All")); $grid->setSelect("ftp","select distinct ftp, ftp ftpList from portaudit order by ftp",false,false,true,array(""=>"All")); $grid->setSelect("ssh","select distinct ssh, ssh sshList from portaudit order by ssh",false,false,true,array(""=>"All")); $grid->setSelect("telnet","select distinct telnet, telnet telnetList from portaudit order by telnet",false,false,true,array(""=>"All")); $grid->setSelect("rsh","select distinct rsh, rsh rshList from portaudit order by rsh",false,false,true,array(""=>"All")); $grid->setSelect("rlogin","select distinct rlogin, rlogin rloginList from portaudit order by rlogin",false,false,true,array(""=>"All")); $grid->navigator = true; $grid->setNavOptions('navigator',array("excel"=>true,"csv"=>true,"add"=>false,"edit"=>false,"del"=>false,"search"=>true,"view"=>true)); $grid->setNavOptions('search', array("multipleGroup"=>true,"showQuery"=>true)); $grid->setNavOptions('view',array("width"=>350,"height"=>400,"dataheight"=>300,"top"=>150,"left"=>250)); $grid->renderGrid('#grid','#pager',true,null,null,true,true); |
This is working in that it sets the $where variable correctly, however since the toolbar filters don’t reload when the grid reloads the option lists for the subsequent columns don’t get repopulated.
Is the a way to cause the selSelects to all refresh along with the grid?
Ken
Copyright 2014 TriRand LtdAll Rights ReservedRSS
Back to Top