On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • Hi,
    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.

    This question has been answered by Bruno17. See the first response.

    • I have solve this, but there is some crutch programming, I think...

      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.
      • discuss.answer
        doesn't it work with default-values of '_empty' ?
          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
        • Wow!!!

          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.