FineUI 官方论坛
标题:
FineUI Filter Builder
[打印本页]
作者:
棕榈
时间:
2020-1-21 17:33
标题:
FineUI Filter Builder
FineUI Filter Builder
[attach]12203[/attach]
参考了 devexpress
在 FineUI 的 Tree 组件上构建的过滤生成器,它的应用很广泛,不仅可以用于最终用户,也可以用于后台的设置,同时也可以结合规则引擎,为其创建规则条件。
1、它本身包含了一些操作符,同时也可以增加新的操作符
2、组及条件都可以单独定义操作符
2、值支持文本、数字、布尔、日期等类型
3、可以增加删除组及条件
4、组的个数及嵌套没有限制
5、可以自定义下拉列表,同时支持单选及多选
6、可以生成过滤,同时也可以导入过滤
下面是字段的定义及过滤代码:
@page
@model FineUICore.EmptyProject.RazorPages.Pages.FilterBuilderModel
@section body{
<f:Tree ID="Tree1" ShowHeader="true" Title="Filter Builder" EnableCollapse="false" EnableIcons="false">
</f:Tree>
<br />
<f:Panel Layout="Fit" Title="Filter" Height="200" BodyPadding="10">
<Items>
<f:TextArea ID="TextArea1"></f:TextArea>
</Items>
</f:Panel>
<br />
<f:Button Text="获取Filter" OnClientClick="getFilter()"></f:Button>
<f:Button Text="设置Filter" OnClientClick="setFilter()"></f:Button>
}
@section script{
<script src="~/fineui-filter-builder.js"></script>
<script>
var fields = [
{
"name": "name",
"text": "姓名",
"dataType": "string"
},
{
"name": "gender",
"text": "性别",
"dataType": "string",
"operators": ["=", "<>", "isnull", "notnull"],
"options": {
"data": [
["1", "男"],
["2", "女"]
]
}
},
{
"name": "age",
"text": "年龄",
"dataType": "number"
},
{
"name": "entranceYear",
"text": "入学年份",
"dataType": "date",
"operators": [
"=",
"<>",
"<",
">",
"<=",
">=",
"between",
[
"customize",
"自定义",
{
"data": [
["1", "前年"],
["2", "去年"],
["3", "今年"]
],
"multiValue": true
}
]
]
},
{
"name": "atSchool",
"text": "是否在校",
"dataType": "boolean",
"operators": ["=", "<>", ["all", "所有", false]],
"options": {
"data": [
["yes", "在校"],
["no", "离校"]
]
}
},
{
"name": "major",
"text": "所学专业",
"dataType": "string",
"operators": [
"=",
"<>",
"isnull",
"notnull",
["anyof", "任意一个", { "multiValue": true }]
],
"options": {
"data": ["化学系", "数学系", "物理系", "自动化系", "材料科学与工程系"]
}
},
{
"name": "logTime",
"text": "注册日期",
"dataType": "date"
}
];
var groups = [["and", "并且"], ["or", "或者"]];
var filter = {
"operator": "and",
"items": [
{
"field": "name",
"operator": "contains",
"value": "张"
},
{
"operator": "or",
"items": [
{
"field": "age",
"operator": ">=",
"value": 23
},
{
"field": "atSchool",
"operator": "=",
"value": "yes"
},
{
"field": "major",
"operator": "=",
"value": "物理系"
}
]
}
]
};
var filterBuilder = null;
function getFilter() {
F.ui.TextArea1.setText(JSON.stringify(filterBuilder.outputFilter(), null, 2));
}
function setFilter() {
filterBuilder.inputFilter(JSON.parse(F.ui.TextArea1.getText()));
}
F.ready(function () {
filterBuilder = F.ext.createFilterBuilder("Tree1");
filterBuilder.setFields(fields);
filterBuilder.setGroups(groups);
filterBuilder.inputFilter(filter);
});
</script>
}
复制代码
作者:
sanshi
时间:
2020-1-23 22:53
厉害!厉害!
作者:
竹席
时间:
2020-2-12 17:52
sanshi 发表于 2020-1-23 22:53
厉害!厉害!
把收藏功能开启啊
欢迎光临 FineUI 官方论坛 (https://fineui.com/bbs/)
Powered by Discuz! X3.4