简体   繁体   中英

Filter values in phpgrid

I am using phpgrid.com's datagrid and want to make a column named products by filtering and allowing only certain products and not all. Now can i do this?

$dg = new C_DataGrid("SELECT kbid,type,issuesummary,productid,priority,createddate,lastupdated,status,resolution,assigneduserid FROM issues", "kbid", "orders");
$dg->set_col_title("kbid", "KBID");
$dg->set_col_width("kbid", 50);
$dg->set_col_title("type", "Type");
$dg->set_col_width("type", 50);
$dg->set_col_title("issuesummary", "Summary");
$dg->set_col_width("issuesummary", 300);
$dg->set_col_title("productid", "Product");
$dg->set_col_width("productid", 70);
$dg->set_col_title("priority", "Priority");
$dg->set_col_width("priority", 70);
$dg->set_col_title("createddate", "Reported");
$dg->set_col_width("createddate", 50);
$dg->set_col_title("lastupdated", "Updated");
$dg->set_col_width("lastupdated", 50);
$dg->set_col_title("status", "Status");
$dg->set_col_width("status", 50);
$dg->set_col_title("resolution", "Resolution");
$dg->set_col_width("resolution", 50);
$dg->set_col_title("assigneduserid", "Assigned");
$dg->set_col_width("assigneduserid", 70);
$dg -> enable_resize(false);
$dg -> set_caption("Issue Base");
$dg->enable_kb_nav(true);
$dg -> enable_search(true);
$dg -> set_dimension(1300, 460);
$dg -> set_col_edittype('status', 'select', 'OP:Open;CL:Closed;DF:Deferred;VE:Vendor;FQ:FAQ');
$dg -> set_col_edittype('type', 'select', 'IP:IP;IT:IT;UP:UP;UQ:UQ;UW:UW;IF:IF;UF:UF;IW:IW;DI:DI');
$dg -> set_col_edittype('priority', 'select', '0:None;1:Urgent;2:High;3:Medium;4:Low;5:Lowest');
$dg -> set_col_edittype('resolution', 'select', 'PP:Pending Review;FX:Fixed;UR:Unreproducable;AD:As Designed;UF:Unable to Fix;WD:Withdrawn;NI:Need More Info;AS:Assigned;WK:Working on Issue;TS:Testing Issue;RJ:Rejected;UF:Temporary Fix;AC:Accepted');
$dg -> set_col_edittype('productid', 'select', '17:ALCS/GI;20:ALCS/ZAS;125:Beta zTPFGI;16:RTF;114:zTPFGI');
$dg -> set_col_edittype('assigneduserid', 'select', $y);
$dg -> set_col_property("lastupdated", array("formatter"=>"date","formatoptions"=>array("srcformat"=>"ISO8601Short","newformat"=>"d-m-Y")));
$dg -> set_col_property("createddate", array("formatter"=>"date","formatoptions"=>array("srcformat"=>"ISO8601Short","newformat"=>"d-m-Y")));
$dg->set_pagesize(30);
$dg->enable_export('EXCEL');
$dg->display(); 

I wanna filter the column productid and allow only values 16,17,20,114,125 to be displayed.

First of all, I believe the first line is wrong. The last parameter is always the table name as noted here:

http://phpgrid.com/example/example-1-a-basic-php-datagrid-2/

Note that the 3rd parameter is ALWAYS equals to the database table name, not alias or any arbitrary name (see below).

phpgrid构造函数第3个参数

The correct line is:

$dg = new C_DataGrid("SELECT kbid,type,issuesummary,productid,priority,createddate,lastupdated,status,resolution,assigneduserid FROM issues", "kbid", "issues");

Now, back to your question, you need to use set_query_filter to filter data. It basically adds WHERE sql clause and does filter from database before renders the grid. http://phpgrid.com/documentation/set_query_filterwhere/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM