extjs - 如何正确添加过滤器和过滤数据?
问题描述
我有窗口 ExtJS:
let height = Ext.getBody().getViewSize().height,
width = Ext.getBody().getViewSize().width,
store = Ext.create('CRM.store.MessageCenter.Messages.List');
Ext.define('CRM.window.MessageCenter.Messages.List', {
extend: 'Ext.window.Window',
xtype: 'window',
name: 'MessageCenter_Messages_List_Window',
iconCls: 'mails',
title: 'MessageCenter_Messages',
width: width,
height: height - 26,
x: 0,
y: 26,
layout: 'fit',
dockedItems: [{
xtype: 'pagingtoolbar',
dock: 'bottom',
displayInfo: true,
extend: 'Ext.PagingToolbar',
displayMsg: 'Shown {0} - {1} from {2}',
emptyMsg: "There is no data to display",
}],
initComponent: function() {
var that = this;
that.store = store;
that.dockedItems[0].store = store;
this.callParent();
},
items: [{
xtype: 'grid',
name: 'MessageCenter_Messages_List_Grid',
border: false,
store: store,
columns: [
{
text: 'ID',
dataIndex: 'id',
width: 100,
hidden: false
},
{
text: 'Date of creation',
dataIndex: 'date',
width: 150,
xtype: 'datecolumn',
format: 'd.m.Y H:i:s',
hidden: false
},
],
}],
});
我的店铺:
let name = 'CRM.store.MessageCenter.Messages.List';
Ext.define(name, {
extend: 'Ext.data.Store',
autoLoad: true,
pageSize: 35,
fields: [
'id',
'date',
],
sorters: [{
property: 'date',
direction: 'DESC',
}],
proxy: {***},
});
我需要添加过滤器以从数据库中选择数据。例如,按日期或 ID,但我不知道如何正确执行。以及在我的情况下是否有必要使用数据模型。请告诉我,我刚开始学习 ExtJS,谢谢你的帮助。
解决方案
没有必要使用数据模型(但它会很好)。要使用用户定义的过滤器,您可以使用此插件。AFAIK您需要远程过滤器,因此将商店的“remoteFilter”属性设置为true。类似于以下示例:
Ext.create('Ext.grid.Panel', {
renderTo: Ext.getBody(),
title: 'Sci-Fi Television',
height: 250,
store: Ext.create('Ext.data.Store', {
fields: ['id', 'show'],
model: 'User',
proxy: {
type: 'ajax',
url: 'data1.json',
reader: {
type: 'json',
rootProperty: 'items'
}
},
autoLoad: true,
remoteFilter: true, // Server side filtering.
}),
plugins: 'gridfilters',
columns: [{
dataIndex: 'id',
text: 'ID',
width: 50
}, {
dataIndex: 'show',
text: 'Show',
flex: 1,
filter: {
// required configs
type: 'string',
// optional configs
value: 'star', // setting a value makes the filter active.
itemDefaults: {
// any Ext.form.field.Text configs accepted
}
}
}]
});
此示例将发送以下过滤器属性:
[{"operator":"like","value":"starrr","property":"show"}]
推荐阅读
- amazon-web-services - 使用 AWS Rekognition 或 Google Vision API 对位模糊文本进行 OCR
- spring - 如何在 Spring Web Service 请求中删除不需要的命名空间并更改命名空间位置
- selenium - 尝试为 MMT 站点执行此代码时出错
- javascript - 班级组合不应用新风格
- bash - 用 IP 地址替换参数
- excel - Excel Vlookup 公式疑难解答
- python - 使用网络抓取检查商品是否有货
- python - 如何使用 libtorrent 将 set_sequential_download() 添加到此代码中?
- java - 清除任务后如何返回上一个活动?
- hugo - 如何创建没有直接链接的 HUGO 页面