假设您在服务器端使用 PHP/MySQL,我会使用这种方法:
在过滤器输入中输入类似Open|Closed 的内容。 (或使用任何你喜欢的分隔符)
此搜索字符串将发送到您的服务器。
在服务器explode()这个搜索字符串变成一个数组。
$search=explode("|",$searchstring);
然后从该数组生成一个 sql 查询。
示例代码:
//The searchstring that was send via ajax
$searchstring="Open|Closed";
//The field in the DB you want to filter
$field="status";
//Generate the where condition
$search=explode("|",$searchstring);
$whereCond="";
while (list($key, $val) = each($search)) {
$whereCond.= "`".$field."` ='".$val."' OR " ;
}
//remove the last unnecessary OR
$whereCond = substr_replace( $whereCond, "", -3 );
//Generate the query
$query="SELECT * FROM `table` WHERE ( ".$whereCond." )";
//Fetch data from the DB and return it to your App
这应该生成如下查询:
SELECT * FROM `table` WHERE ( `status` ='Open' OR `status` ='Closed' )
这样您可以输入任意数量的OR条件。
注意适当数量的空格并在查询中使用正确的引号。
如果您使用另一个堆栈,则必须找出自己的查询生成器。但基本上它归结为这种方法。如果您使用的是服务器端数据,则必须在服务器端进行过滤。
可以在官方 ng-grid 网站here 上找到客户端示例。
服务器端分页示例实际上是客户端,它只是从服务器获取一个大的 json 文件。