|
|
@@ -0,0 +1,705 @@
|
|
|
+/*
|
|
|
+ * @Description: 列表筛选头
|
|
|
+ * @Author: hy
|
|
|
+ * @Date: 2019-07-29 15:22:51
|
|
|
+ * @LastEditTime: 2019-08-12 18:38:13
|
|
|
+ */
|
|
|
+Ext.define('uas.view.plugins.gridHeaderFilter.GridHeaderFilter', {
|
|
|
+ extend: 'Ext.plugin.Abstract',
|
|
|
+ alias: 'plugin.gridHeaderFilter',
|
|
|
+ mixins: [
|
|
|
+ 'Ext.util.StoreHolder'
|
|
|
+ ],
|
|
|
+ requires: [
|
|
|
+ 'Ext.grid.filters.filter.*',
|
|
|
+ 'uas.view.plugins.gridHeaderFilter.field.*'
|
|
|
+ ],
|
|
|
+ id: 'gridHeaderFilter',
|
|
|
+ /**
|
|
|
+ * @property {Object} defaultFilterTypes
|
|
|
+ * This property maps {@link Ext.data.Model#cfg-fields field type} to the
|
|
|
+ * appropriate grid filter type.
|
|
|
+ * @private
|
|
|
+ */
|
|
|
+ defaultFilterTypes: {
|
|
|
+ 'boolean': 'boolean',
|
|
|
+ 'int': 'number',
|
|
|
+ date: 'date',
|
|
|
+ number: 'number'
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * @property {String} [filterCls="x-grid-filters-filtered-column"]
|
|
|
+ * The CSS applied to column headers with active filters.
|
|
|
+ */
|
|
|
+ filterCls: Ext.baseCSSPrefix + 'grid-filters-filtered-column',
|
|
|
+ /**
|
|
|
+ * @cfg {String} [menuFilterText]
|
|
|
+ * The text for the filters menu.
|
|
|
+ * @locale
|
|
|
+ */
|
|
|
+ menuFilterText: 'Filters',
|
|
|
+ /**
|
|
|
+ * @cfg {Boolean} showMenu
|
|
|
+ * Defaults to true, including a filter submenu in the default header menu.
|
|
|
+ */
|
|
|
+ showMenu: true,
|
|
|
+ /**
|
|
|
+ * @cfg {String} stateId
|
|
|
+ * Name of the value to be used to store state information.
|
|
|
+ */
|
|
|
+ stateId: undefined,
|
|
|
+ init: function (grid) {
|
|
|
+ var me = this,store;
|
|
|
+ Ext.Assert.falsey(me.grid);
|
|
|
+ me.grid = grid;
|
|
|
+ grid.filters = me;//绑定到grid
|
|
|
+ if (me.grid.normalGrid) {
|
|
|
+ me.isLocked = true;
|
|
|
+ }
|
|
|
+ grid.clearFilters = me.clearFilters.bind(me);//清除过滤绑定到grid
|
|
|
+ grid.getHeaderFilter = me.getHeaderFilter.bind(me);//清除过滤绑定到grid
|
|
|
+ store = grid.store;
|
|
|
+
|
|
|
+ me.gridListeners = grid.on({
|
|
|
+ destroyable: true,
|
|
|
+ scope: me,
|
|
|
+ reconfigure: me.onReconfigure
|
|
|
+ });
|
|
|
+ if (store.isEmptyStore) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ me.initColumns();
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * Creates the Filter objects for the current configuration.
|
|
|
+ * Reconfigure and on add handlers.
|
|
|
+ * @private
|
|
|
+ */
|
|
|
+ initColumns: function () {
|
|
|
+ var grid = this.grid,
|
|
|
+ store = grid.getStore(),
|
|
|
+ columns = grid.columnManager.getColumns(),
|
|
|
+ len = columns.length,
|
|
|
+ i, column, filter, filterCollection;
|
|
|
+ // We start with filters defined on any columns.
|
|
|
+ for (i = 0; i < len; i++) {
|
|
|
+ column = columns[i];
|
|
|
+ filter = column.filter;
|
|
|
+ if (filter) {
|
|
|
+ if (!filterCollection) {
|
|
|
+ filterCollection = store.getFilters();
|
|
|
+ filterCollection.beginUpdate();
|
|
|
+ }
|
|
|
+ this.createColumnFilter(column);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (filterCollection) {
|
|
|
+ filterCollection.endUpdate();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 根据类型生成不同的筛选头
|
|
|
+ */
|
|
|
+ createColumnFilter: function (column) {
|
|
|
+ const me = this;
|
|
|
+ const filter = column.filter;
|
|
|
+ if(!column.hasHeaderField && !column.hidden){
|
|
|
+ if(typeof filter.type === 'string'){
|
|
|
+ switch (filter.type) {
|
|
|
+ case 'string':
|
|
|
+ me.createStringFilter(column);
|
|
|
+ column.hasHeaderField = true
|
|
|
+ break;
|
|
|
+ case 'number':
|
|
|
+ me.createNumberFilter(column);
|
|
|
+ column.hasHeaderField = true
|
|
|
+ break;
|
|
|
+ case 'combo':
|
|
|
+ me.createComboFilter(column,filter.combo);
|
|
|
+ column.hasHeaderField = true
|
|
|
+ break;
|
|
|
+ case 'date':
|
|
|
+ me.createDateFilter(column);
|
|
|
+ column.hasHeaderField = true
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 为toolbar添加标签
|
|
|
+ */
|
|
|
+ addTips:function(column,filterToolbar,text){
|
|
|
+ filterToolbar.add({
|
|
|
+ iconCls:'x-btn-field-clear',
|
|
|
+ xtype: 'button',
|
|
|
+ text: text,
|
|
|
+ iconAlign: 'right',
|
|
|
+ handler:function(btn){
|
|
|
+ if( window.event && window.event.target && window.event.target.getAttribute('id')
|
|
|
+ && window.event.target.getAttribute('id').indexOf('-btnIconEl')>-1 ){
|
|
|
+ if(column.filterContainer.input.xtype==="resetComboField"){
|
|
|
+ column.filterContainer.input.setValue([]);
|
|
|
+ }else{
|
|
|
+ column.filterContainer.input.setValue(null);
|
|
|
+ }
|
|
|
+ filterToolbar.remove(btn);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 将筛选条件转换成sql
|
|
|
+ * @param {}
|
|
|
+ * @return: SQLString
|
|
|
+ */
|
|
|
+ getHeaderFilter:function(){
|
|
|
+ const me = this;
|
|
|
+ const { grid } = me;
|
|
|
+ const columns = grid.getColumns();
|
|
|
+ const filterToolbar = grid.down('[name=filterToolbar]');
|
|
|
+ filterToolbar.removeAll();
|
|
|
+ let condition = [];
|
|
|
+ columns.map(column=>{
|
|
|
+ if(column.hasHeaderField && column.filterContainer ){
|
|
|
+ let con = column.filterContainer.getCondition();
|
|
|
+ if(con){
|
|
|
+ condition.push(con);
|
|
|
+ //更新toolbar
|
|
|
+ let text = `${column.text}/${column.filterContainer.operator.operateText} : <span style="color:#ff0000">${con.value[0]}</span>`
|
|
|
+ switch (con.type) {
|
|
|
+ case 'string':
|
|
|
+ if(con.operate==='isNull'){
|
|
|
+ text = `${column.text} : <span style="color:#ff0000">${con.value[0]}</span>`
|
|
|
+ }
|
|
|
+ me.addTips(column,filterToolbar,text);
|
|
|
+ break;
|
|
|
+ case 'number':
|
|
|
+ if(con.operate==='~'){
|
|
|
+ text = `${column.text} : <span style="color:#ff0000">${con.value[0].split('~')[0]} ~ ${con.value[0].split('~')[1]}</span>`
|
|
|
+ }else{
|
|
|
+ text = `${column.text} <span style="color:#ff0000">${isNaN(Number(con.value[0]))?con.value[0]:(con.operate+con.value[0])}</span>`
|
|
|
+ }
|
|
|
+ me.addTips(column,filterToolbar,text);
|
|
|
+ break;
|
|
|
+ case 'combo':
|
|
|
+ text = `${column.text}/${column.filterContainer.operator.operateText} : <span style="color:#ff0000">${con.value.join(',')}</span>`
|
|
|
+ me.addTips(column,filterToolbar,text);
|
|
|
+ break;
|
|
|
+ case 'date':
|
|
|
+
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // condition = Ext.JSON.encodeValue(condition, '\n').replace(/^[ ]+/gm, function (s) {
|
|
|
+ // for (var r = '', i = s.length; i--;) {
|
|
|
+ // r += ' ';
|
|
|
+ // }
|
|
|
+ // return r;
|
|
|
+ // });
|
|
|
+ // condition = condition.replace(/\n/g, '<br>');
|
|
|
+ // Ext.toast({
|
|
|
+ // html: condition,
|
|
|
+ // closable: false,
|
|
|
+ // align: 't',
|
|
|
+ // slideDUration: 400,
|
|
|
+ // maxWidth: 400
|
|
|
+ // });
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 时间日期过滤头
|
|
|
+ */
|
|
|
+ createDateFilter:function(column){
|
|
|
+ const me = this;
|
|
|
+ let config = {
|
|
|
+ xtype:'resetDateField'
|
|
|
+ };
|
|
|
+ //下拉按钮
|
|
|
+ let operator = {
|
|
|
+ xtype:'operateButton',
|
|
|
+ operateText: '等于',
|
|
|
+ operate: "equal"
|
|
|
+ };
|
|
|
+ //筛选头容器
|
|
|
+ let DateFilter = {
|
|
|
+ xtype:'filterContainer',
|
|
|
+ inputType:config.xtype,
|
|
|
+ items:[ config,operator ],
|
|
|
+ getCondition:function(){
|
|
|
+ const me = this;
|
|
|
+ let items = [],value=[];
|
|
|
+ const { operator,input } = me;
|
|
|
+ const inputV = input.getValue();
|
|
|
+ if(inputV && Ext.isString(inputV)){
|
|
|
+ items = inputV.split(',');
|
|
|
+ items.map(item=>{
|
|
|
+ input.datas.map(data=>{
|
|
|
+ if(data[1]===item){
|
|
|
+ value.push(data[0])
|
|
|
+ }
|
|
|
+ })
|
|
|
+ });
|
|
|
+ return {
|
|
|
+ type: 'combo',
|
|
|
+ operate: operator.operate,
|
|
|
+ field: column.dataIndex,
|
|
|
+ value: value
|
|
|
+ };
|
|
|
+ }else{
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ //加入到表头
|
|
|
+ let filterContainer = column.insert(0,DateFilter);
|
|
|
+ //绑定到列
|
|
|
+ column.filterContainer = filterContainer;
|
|
|
+ filterContainer.items.items.map((item)=>{
|
|
|
+ item.on({
|
|
|
+ scope: me,
|
|
|
+ keyup: Ext.emptyFn,
|
|
|
+ el: {
|
|
|
+ click: function(e) {
|
|
|
+ e.stopPropagation();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 下拉框过滤头
|
|
|
+ */
|
|
|
+ createComboFilter:function(column,combo){
|
|
|
+ const me = this;
|
|
|
+ let config = {
|
|
|
+ xtype:'resetComboField',
|
|
|
+ datas:combo||[]
|
|
|
+ };
|
|
|
+ //下拉按钮
|
|
|
+ let operator = {
|
|
|
+ xtype:'operateButton',
|
|
|
+ operateText: '包括',
|
|
|
+ operate: "in"
|
|
|
+ };
|
|
|
+ //筛选头容器
|
|
|
+ let ComboFilter = {
|
|
|
+ xtype:'filterContainer',
|
|
|
+ inputType:config.xtype,
|
|
|
+ items:[ config,operator ],
|
|
|
+ getCondition:function(){
|
|
|
+ const me = this;
|
|
|
+ let items = [],value=[];
|
|
|
+ const { operator,input } = me;
|
|
|
+ const inputV = input.getValue();
|
|
|
+ if(inputV && Ext.isString(inputV)){
|
|
|
+ items = inputV.split(',');
|
|
|
+ items.map(item=>{
|
|
|
+ input.datas.map(data=>{
|
|
|
+ if(data[1]===item){
|
|
|
+ value.push(data[0])
|
|
|
+ }
|
|
|
+ })
|
|
|
+ });
|
|
|
+ return {
|
|
|
+ type: 'combo',
|
|
|
+ operate: operator.operate,
|
|
|
+ field: column.dataIndex,
|
|
|
+ value: value
|
|
|
+ };
|
|
|
+ }else{
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ //加入到表头
|
|
|
+ let filterContainer = column.insert(0,ComboFilter);
|
|
|
+ //绑定到列
|
|
|
+ column.filterContainer = filterContainer;
|
|
|
+ filterContainer.items.items.map((item)=>{
|
|
|
+ item.on({
|
|
|
+ scope: me,
|
|
|
+ keyup: Ext.emptyFn,
|
|
|
+ el: {
|
|
|
+ click: function(e) {
|
|
|
+ e.stopPropagation();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数字过滤头
|
|
|
+ */
|
|
|
+ createNumberFilter:function(column){
|
|
|
+ const me = this;
|
|
|
+ //逻辑按钮
|
|
|
+ let operator = {
|
|
|
+ xtype:'operateButton',
|
|
|
+ operateText: '等于',
|
|
|
+ operate: "=",
|
|
|
+ menu: {
|
|
|
+ xtype:'filterMenu',
|
|
|
+ width:220,
|
|
|
+ maxWidth:220,
|
|
|
+ defaults:{
|
|
|
+ xtype:'menuNumberField'
|
|
|
+ },
|
|
|
+ items:[{
|
|
|
+ fieldLabel:'等于',
|
|
|
+ operate: "="
|
|
|
+ },{
|
|
|
+ fieldLabel: '不等于',
|
|
|
+ operate: "!="
|
|
|
+ },{
|
|
|
+ fieldLabel: '大于',
|
|
|
+ operate: ">"
|
|
|
+ },{
|
|
|
+ fieldLabel: '大于等于',
|
|
|
+ operate: ">="
|
|
|
+ },{
|
|
|
+ fieldLabel: '小于',
|
|
|
+ operate: "<"
|
|
|
+ },{
|
|
|
+ fieldLabel: '小于等于',
|
|
|
+ operate: "<="
|
|
|
+ },{
|
|
|
+ fieldLabel: '介于',
|
|
|
+ xtype: 'container',
|
|
|
+ layout: 'hbox',
|
|
|
+ operate: "~",
|
|
|
+ margin:'2 5 0 0',
|
|
|
+ items:[{
|
|
|
+ margin:'6 0 0 10',
|
|
|
+ xtype:'displayfield',
|
|
|
+ value:'介于: '
|
|
|
+ },{
|
|
|
+ width:77,
|
|
|
+ hideLabel:true,
|
|
|
+ xtype:'menuNumberField'
|
|
|
+ },{
|
|
|
+ margin:'6 0 0 0',
|
|
|
+ xtype:'displayfield',
|
|
|
+ value:'~ '
|
|
|
+ },{
|
|
|
+ width:77,
|
|
|
+ hideLabel:true,
|
|
|
+ xtype:'menuNumberField'
|
|
|
+ }],
|
|
|
+ setValue:function(v){
|
|
|
+ const me = this;
|
|
|
+ //校验Value 符合条件则赋值
|
|
|
+ let v1=null,v2=null;
|
|
|
+ if(v&&v.indexOf('~')>-1){
|
|
|
+ let arr = v.split('~');
|
|
|
+ if(arr[0]){ v1 = arr[0]; }
|
|
|
+ if(arr[1]){ v2 = arr[1]; }
|
|
|
+ }
|
|
|
+ me.items.items.map((item,index)=>{
|
|
|
+ if(item.xtype==="menuNumberField"){
|
|
|
+ if(index === 1){
|
|
|
+ item.setValue(v1);
|
|
|
+ }else{
|
|
|
+ item.setValue(v2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(index===0){
|
|
|
+ if(v1 || v2){
|
|
|
+ item.inputEl.dom.classList.add('x-menu-label-select')
|
|
|
+ }else{
|
|
|
+ item.inputEl.dom.classList.remove('x-menu-label-select')
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //带清除按钮的输入框1 选择逻辑类型为介于时显示
|
|
|
+ let config = {
|
|
|
+ xtype:'resetNumberField'
|
|
|
+ }
|
|
|
+ //筛选头容器
|
|
|
+ let NumberFilter = {
|
|
|
+ xtype:'filterContainer',
|
|
|
+ inputType:config.xtype,
|
|
|
+ items:[ config,operator ],
|
|
|
+ getCondition:function(){
|
|
|
+ const me = this;
|
|
|
+ const { operator,input } = me;
|
|
|
+ const inputV = input.getValue();
|
|
|
+ if(inputV){
|
|
|
+ if(operator.fieldLabel==='介于'){
|
|
|
+ return {
|
|
|
+ type: 'number',
|
|
|
+ operate: operator.operate,
|
|
|
+ field: column.dataIndex,
|
|
|
+ value: [inputV.split('~')[0],inputV.split('~')[1]]
|
|
|
+ };
|
|
|
+ }else{
|
|
|
+ return {
|
|
|
+ type: 'number',
|
|
|
+ operate: operator.operate,
|
|
|
+ field: column.dataIndex,
|
|
|
+ value: [inputV]
|
|
|
+ };
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //加入到表头
|
|
|
+ let filterContainer = column.insert(0,NumberFilter);
|
|
|
+ //绑定到列
|
|
|
+ column.filterContainer = filterContainer;
|
|
|
+ filterContainer.items.items.map((item)=>{
|
|
|
+ item.on({
|
|
|
+ scope: me,
|
|
|
+ keyup: Ext.emptyFn,
|
|
|
+ el: {
|
|
|
+ click: function(e) {
|
|
|
+ e.stopPropagation();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 字符串过滤头
|
|
|
+ */
|
|
|
+ createStringFilter:function(column){
|
|
|
+ const me = this;
|
|
|
+ //逻辑按钮
|
|
|
+ let operator = {
|
|
|
+ xtype:'operateButton',
|
|
|
+ operate: 'like',
|
|
|
+ operateText: '包含',
|
|
|
+ menu: {
|
|
|
+ xtype:'filterMenu',
|
|
|
+ width:200,
|
|
|
+ maxWidth:200,
|
|
|
+ defaults:{
|
|
|
+ xtype:'menuTextField'
|
|
|
+ },
|
|
|
+ items:[{
|
|
|
+ fieldLabel:'包含',
|
|
|
+ operate: "like"
|
|
|
+ },{
|
|
|
+ fieldLabel: '不包含',
|
|
|
+ operate: "notLike"
|
|
|
+ },{
|
|
|
+ fieldLabel: '开头是',
|
|
|
+ operate: "first"
|
|
|
+ },{
|
|
|
+ fieldLabel: '结尾是',
|
|
|
+ operate: "last"
|
|
|
+ },{
|
|
|
+ fieldLabel: '等于',
|
|
|
+ operate: "equal"
|
|
|
+ },{
|
|
|
+ fieldLabel: '不等于',
|
|
|
+ operate: "unEqual",
|
|
|
+ },{
|
|
|
+ margin:'5 0 0 20',
|
|
|
+ labelWidth:70,
|
|
|
+ xtype: 'checkbox',
|
|
|
+ fieldLabel: '空(未填写)',
|
|
|
+ operate: "isNull",
|
|
|
+ listeners:{
|
|
|
+ change:function(me,newValue,oldValue){
|
|
|
+ const menu = me.up();
|
|
|
+ const container = menu.up().up();
|
|
|
+ const { operator,input }= container;
|
|
|
+ const grid = container.up().up().up();
|
|
|
+ if(window.event.target.getAttribute('id').indexOf('checkboxfield')>-1){
|
|
|
+ //清除其它输入框
|
|
|
+ menu.items.items.map(item=>{
|
|
|
+ if(item.operate!==me.operate){
|
|
|
+ item.setValue(null);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ if(input.value && input.value === me.fieldLabel){
|
|
|
+ input.setValue(null)
|
|
|
+ operator.operate = "like";
|
|
|
+ operator.operateText = '包含';
|
|
|
+ }else{
|
|
|
+ input.setValue(me.fieldLabel);
|
|
|
+ operator.operate = me.operate;
|
|
|
+ operator.operateText = me.fieldLabel;
|
|
|
+ }
|
|
|
+ grid.getHeaderFilter();
|
|
|
+ menu.hide();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //带清除按钮的输入框
|
|
|
+ let config = {
|
|
|
+ xtype:'resetTextField',
|
|
|
+ }
|
|
|
+ //筛选头容器
|
|
|
+ let StringFilter = {
|
|
|
+ xtype:'filterContainer',
|
|
|
+ inputType:config.xtype,
|
|
|
+ items:[ config, operator ],
|
|
|
+ getCondition:function(){
|
|
|
+ const column = this.up();
|
|
|
+ const logic = this.operator.operate;
|
|
|
+ const inputV = this.input.getValue();
|
|
|
+ if(inputV){
|
|
|
+ return {
|
|
|
+ type: 'string',
|
|
|
+ operate: logic,
|
|
|
+ field: column.dataIndex,
|
|
|
+ value: [inputV]
|
|
|
+ };
|
|
|
+ }else{
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //加入到表头
|
|
|
+ let filterContainer = column.insert(0,StringFilter);
|
|
|
+ //绑定到列
|
|
|
+ column.filterContainer = filterContainer;
|
|
|
+ //更改作用域
|
|
|
+ filterContainer.items.items.map((item)=>{
|
|
|
+ item.on({
|
|
|
+ scope: me,
|
|
|
+ keyup: Ext.emptyFn,
|
|
|
+ el: {
|
|
|
+ click: function(e) {
|
|
|
+ e.stopPropagation();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ destroy: function () {
|
|
|
+ var me = this,
|
|
|
+ filterMenuItem = me.filterMenuItem,
|
|
|
+ item;
|
|
|
+ Ext.destroy(me.headerCtListeners, me.gridListeners, me.headerMenuListeners);
|
|
|
+ me.sep = Ext.destroy(me.sep);
|
|
|
+ for (item in filterMenuItem) {
|
|
|
+ filterMenuItem[item].destroy();
|
|
|
+ }
|
|
|
+ this.callParent();
|
|
|
+ },
|
|
|
+ getHeaders: function () {
|
|
|
+ return this.grid.view.headerCt.columnManager.getColumns();
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * Checks the plugin's grid for statefulness.
|
|
|
+ * @return {Boolean}
|
|
|
+ */
|
|
|
+ isStateful: function () {
|
|
|
+ return this.grid.stateful;
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * Adds a filter to the collection and creates a store filter if has a `value` property.
|
|
|
+ * @param {Object/Object[]/Ext.util.Filter/Ext.util.Filter[]} filters A filter
|
|
|
+ * configuration or a filter object.
|
|
|
+ */
|
|
|
+ clearFilters: function () {
|
|
|
+ var grid = this.grid,
|
|
|
+ columns = grid.columnManager.getColumns(),
|
|
|
+ store = grid.store,
|
|
|
+ column, filter, i, len, filterCollection;
|
|
|
+ // We start with filters defined on any columns.
|
|
|
+ for (i = 0, len = columns.length; i < len; i++) {
|
|
|
+ column = columns[i];
|
|
|
+ filter = column.filter;
|
|
|
+ if (filter && filter.isGridFilter) {
|
|
|
+ if (!filterCollection) {
|
|
|
+ filterCollection = store.getFilters();
|
|
|
+ filterCollection.beginUpdate();
|
|
|
+ }
|
|
|
+ filter.setActive(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (filterCollection) {
|
|
|
+ filterCollection.endUpdate();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onReconfigure: function (grid, store, columns, oldStore) {
|
|
|
+ var me = this,
|
|
|
+ filterMenuItem = me.filterMenuItem,
|
|
|
+ changed = oldStore !== store,
|
|
|
+ key;
|
|
|
+ // The Filters item's menu should have already been destroyed by the time we get here but
|
|
|
+ // we still need to null out the menu reference.
|
|
|
+ if (columns) {
|
|
|
+ for (key in filterMenuItem) {
|
|
|
+ //filterMenuItem[key].setMenu(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (store) {
|
|
|
+ if (oldStore && !oldStore.destroyed && changed) {
|
|
|
+ me.resetFilters(oldStore);
|
|
|
+ }
|
|
|
+ if (changed) {
|
|
|
+ me.applyFilters(store);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ me.initColumns();
|
|
|
+ },
|
|
|
+ privates: {
|
|
|
+ applyFilters: function (store) {
|
|
|
+ var columns = this.grid.columnManager.getColumns(),
|
|
|
+ len = columns.length,
|
|
|
+ i, column, filter, filterCollection;
|
|
|
+ // We start with filters defined on any columns.
|
|
|
+ for (i = 0; i < len; i++) {
|
|
|
+ column = columns[i];
|
|
|
+ filter = column.filter;
|
|
|
+ if (filter && filter.isGridFilter) {
|
|
|
+ if (!filterCollection) {
|
|
|
+ filterCollection = store.getFilters();
|
|
|
+ filterCollection.beginUpdate();
|
|
|
+ }
|
|
|
+ if (filter.active) {
|
|
|
+ filter.activate();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (filterCollection) {
|
|
|
+ filterCollection.endUpdate();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ resetFilters: function (store) {
|
|
|
+ var filters = store.getFilters(),
|
|
|
+ i, updating, filter;
|
|
|
+ if (filters) {
|
|
|
+ for (i = filters.getCount() - 1; i >= 0; --i) {
|
|
|
+ filter = filters.getAt(i);
|
|
|
+ if (filter.isGridFilter) {
|
|
|
+ if (!updating) {
|
|
|
+ filters.beginUpdate();
|
|
|
+ }
|
|
|
+ filters.remove(filter);
|
|
|
+ updating = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (updating) {
|
|
|
+ filters.endUpdate();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+});
|