1

我正在使用 phpgrid.com 的数据网格,并希望通过过滤和仅允许某些产品而不是所有产品来创建一个名为 products 的列。现在我可以这样做吗?

$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。

4

1 回答 1

2

首先,我认为第一行是错误的。最后一个参数始终是表名,如此处所述:

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

请注意,第三个参数始终等于数据库表名,而不是别名或任何任意名称(见下文)。

phpgrid 构造函数第三个参数

正确的行是:

$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/

于 2015-02-23T14:07:55.373 回答