I have a grid working with the following code. Not I am not using the cols array at this time. I would like to use the dropdown filter like in the demo folder. Do I need to add cols for each column like your code?
$db_conf = array();
$db_conf["type"] = "mssqlnative"; // or mssql
$db_conf["server"] = "sqlserver"; // ip:port
$db_conf["user"] = null;
$db_conf["password"] = null;
$db_conf["database"] = "Pltdata";
include($base_path."http://www.mysite.com/wp-content/plugins/phpgrid/lib/inc/jqgrid_dist.php");
$g = new jqgrid($db_conf);
$grid["export"]["range"] = "filtered"; // or "all"
$grid["autowidth"] = true; // resize grid with browser resize
$grid["toolbar"] = "top";
$grid["height"] = "750";
table = "[pltdata].[dbo].[Web_BoneyardTable]";
Thanks, do I need to do this for each column in the grade, or just the column I want to filter by
All columns need to be defined, once you customized any column.
I know it's not nice, but that's how it currently work.
Thanks for the help. Have my grid built and everything shows, except i can't get the dropdown working. When I click the dropdown I get "undefined" as the only value showing.
Not sure where my code is wrong..
// begin dropdown column
$col = array();
$col["title"] = "Grade";
$col["name"] = "Grade";
$col["dbname"] = "Web_BoneyardTable.Grade"; # incase of conflict of field name in query, use exact table.field to search in
$col["width"] = "15";
$col["align"] = "left";
$col["search"] = true;
# fetch data from database, with alias k for key, v for value
$grade_lookup = $g->get_dropdown_values("select distinct grade as k from Web_BoneyardTable");
# these 3 lines will make dropdown in search autofilter
$col["stype"] = "select";
// blank row, then all db values – ; is record separator, : is key-value separator
$col["searchoptions"] = array("value" => ":;".$str);
$col["editable"] = true;
$col["edittype"] = "select"; // render as select
$col["editoptions"] = array("value"=> $grade_lookup); // with these values "key:value;key:value;key:value"
$cols[] = $col;
//end dropdown
$g->table = "[pltdata].[dbo].[Web_BoneyardTable]";
// subqueries are also supported now (v1.2)
//$g->select_command = "select * from (select * from invheader) as o";
// pass the cooked columns to grid
$g->set_columns($cols);
Hello,
The only missing element is 'value' in your code.
The following line:
$grade_lookup = $g->get_dropdown_values("select distinct grade as k from Web_BoneyardTable");
should be something like:
$grade_lookup = $g->get_dropdown_values("select distinct grade as k, grade as v from Web_BoneyardTable");
Here i added 'grade as v', to show grade as display value in grid.
Also, make sure this query is returning key:value pair of data.
You can put echo $grade_lookup; die; for debugging.