我正在使用phpgrid.com的数据网格,并希望通过过滤并仅允许某些产品而不是所有产品来创建名为产品的列。我现在可以这样做吗?
$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();
我想过滤柱productid,只允许显示值16,17,20,114,125。
答案 0 :(得分:2)
首先,我认为第一行是错误的。最后一个参数始终是表名,如下所示:
http://phpgrid.com/example/example-1-a-basic-php-datagrid-2/
请注意,第3个参数始终等于数据库表 名称,不是别名或任意名称(见下文)。
正确的行是:
$dg = new C_DataGrid("SELECT kbid,type,issuesummary,productid,priority,createddate,lastupdated,status,resolution,assigneduserid FROM issues", "kbid", "issues");
现在,回到你的问题,你需要使用set_query_filter来过滤数据。它基本上添加了WHERE sql子句,并在呈现网格之前从数据库中进行过滤。 http://phpgrid.com/documentation/set_query_filterwhere/