<![CDATA[ MIGXdb CMP reset filter not working - My Forums]]> https://forums.modx.com/thread/?thread=97925 <![CDATA[MIGXdb CMP reset filter not working]]> https://forums.modx.com/thread/97925/migxdb-cmp-reset-filter-not-working#dis-post-529487 I've made CMP with MIGXdb. Everything works fine, except the resetall filter. There is a settings of all filters:
"filters":[
    {
      "MIGX_id":2,
      "name":"analiz_category",
      "label":"\u0413\u0440\u0443\u043f\u043f\u0430",
      "emptytext":"-\u0432\u044b\u0431\u043e\u0440 \u0433\u0440\u0443\u043f\u043f\u044b-",
      "type":"combobox",
      "getlistwhere":{
        "category":"[[+analiz_category]]"
      },
      "getcomboprocessor":"getcombo",
      "combotextfield":"category",
      "comboidfield":"",
      "comboparent":"",
      "default":""
    },
    {
      "MIGX_id":3,
      "name":"search",
      "label":"\u041f\u043e\u0438\u0441\u043a",
      "emptytext":"\u041f\u043e\u0438\u0441\u043a...",
      "type":"textbox",
      "getlistwhere":{
        "name:LIKE":"%[[+search]]%"
      },
      "getcomboprocessor":"",
      "combotextfield":"",
      "comboidfield":"",
      "comboparent":"",
      "default":""
    },
    {
      "MIGX_id":4,
      "name":"reset",
      "label":"\u0421\u0431\u0440\u043e\u0441\u0438\u0442\u044c",
      "emptytext":"\u0421\u0431\u0440\u043e\u0441\u0438\u0442\u044c",
      "type":"resetall",
      "getlistwhere":"",
      "getcomboprocessor":"",
      "combotextfield":"",
      "comboidfield":"",
      "comboparent":"",
      "default":""
    }
  ]

Please tell me what do I doing wrong. Maybe I need to point to reset filter which filters to process?
I can't find any info about resetall filter in google.

PS Sorry for my poor english.]]>
piterden Aug 04, 2015, 06:20 PM https://forums.modx.com/thread/97925/migxdb-cmp-reset-filter-not-working#dis-post-529487
<![CDATA[Re: MIGXdb CMP reset filter not working]]> https://forums.modx.com/thread/97925/migxdb-cmp-reset-filter-not-working#dis-post-529528
Thanks Bruno, it's really works perfectly. And looks pretty too)

I guess I'm not the first who offer this, but maybe the time to write detailed docs for MIGX has come? I understand that you are very busy man (github not lies), but MIGX have not so small community. If you distribute tasks of writing docs between people from the community, then you can only read and check correctness of it. I think this way going to take much less of your time, but it promises to be productive enough.

Bruno, please think about it. What about me - I always ready to help you and community with it (according on my capabilities), and I suppose I not the only one.]]>
piterden Aug 05, 2015, 02:31 PM https://forums.modx.com/thread/97925/migxdb-cmp-reset-filter-not-working#dis-post-529528
<![CDATA[Re: MIGXdb CMP reset filter not working (Best Answer)]]> https://forums.modx.com/thread/97925/migxdb-cmp-reset-filter-not-working#dis-post-529501 Bruno17 Aug 05, 2015, 03:53 AM https://forums.modx.com/thread/97925/migxdb-cmp-reset-filter-not-working#dis-post-529501 <![CDATA[Re: MIGXdb CMP reset filter not working]]> https://forums.modx.com/thread/97925/migxdb-cmp-reset-filter-not-working#dis-post-529492
After 2 hours of readind MIGX sources, I understand that problem is in function setDefaultFilters() defined in /core/components/migx/templates/mgr/grids/default.grid.tpl
setDefaultFilters: function(){
        var filterDefaults = Ext.util.JSON.decode('{/literal}{$filterDefaults}{literal}');
        var input = null;
        var refresh = false;
        var value = '';
        for (var i=0;i<filterDefaults.length;i++) {
            input = Ext.getCmp(filterDefaults[i].name+'-migxdb-search-filter');
            value = filterDefaults[i].default;
            if (input && value != ''){ 
                if (value == '_empty'){
                    value = '';
                }                
                input.setValue(value);
                this.getStore().baseParams[filterDefaults[i].name]=value;
                refresh = true;
            } 
        }
        if (refresh){
            this.getBottomToolbar().changePage(1);
            this.refresh();            
        }            
                   
    }

This function works perfectly on page refresh, but when i click reset button, it never pass check (input && value != ''). This is because my default values of all filters are empty.
I decided to not edit this function and create new one. Here is my setDefaultFiltersOnClick() function:
setDefaultFiltersOnClick: function(){
        var filterDefaults = Ext.util.JSON.decode('{/literal}{$filterDefaults}{literal}');
        var input = null;
        var refresh = false;
        var value = '';
        for (var i=0;i<filterDefaults.length;i++) {
            input = Ext.getCmp(filterDefaults[i].name+'-migxdb-search-filter');
            value = filterDefaults[i].default;
            if (value == '_empty'){ // I think this block also can be erased
                value = '';
            }
            if (input.xtype == 'textfield' && input.el.dom.value != input.emptyText){
                input.setValue(value);
                this.getStore().baseParams[filterDefaults[i].name]=value;
                refresh = true;
            }
            if (input.xtype == 'modx-combo' && input.value != 'all'){
                value = 'all';
                input.setValue(value);
                this.getStore().baseParams[filterDefaults[i].name]=value;
                refresh = true;
            } 
        }
        if (refresh){
            this.getBottomToolbar().changePage(1);
            this.refresh();            
        }            
                   
    }

It handles only two xtypes of filters for the present, but for my task it is quite enough.

Oh, and of course I don't forget to rename call of function in filter settings file /core/components/migx/configs/grid/grid.filters.inc.php
$gridfilters['resetall']['code']=
"
{
    xtype: 'button'
    ,id: '[[+name]]-migxdb-search-filter'
    ,text: '[[%migx.reset_all]]'
    ,listeners: {
                'click': {
                    fn: function(tf,nv,ov){
                        var s = this.getStore();
                        this.setDefaultFiltersOnClick();  // rename here
                    },
                    scope: this
                }
    }
}
";
//$gridfilters['resetall']['handler'] = 'gridfilter';

So, as I told earlier, it is little bit workaround way. If everybody knows more correct and universal method to do this, I would glad to see it in this topic.]]>
piterden Aug 04, 2015, 08:31 PM https://forums.modx.com/thread/97925/migxdb-cmp-reset-filter-not-working#dis-post-529492