We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 45634
    • 23 Posts
    Hello,

    We've got a data model of Whisky Brands. Each brand can have multiple "expressions" (eg 12yr, 18yr).

    So we have a CMP Grid editor page from this tutorial http://rtfm.modx.com/revolution/2.x/case-studies-and-tutorials/developing-an-extra-in-modx-revolution/developing-an-extra-in-modx-revolution,-part-ii to edit the expressions. See attached picture.

    As you can see each expression has a "Brand ID" column which is an Int. This UI is a bit clumsy and ackward to use ....

    I'm wondering if it's possible to have a CMP editor page that only lets you edit a subset of the data? You could call it with a GET paramater "brandid=1" and that would be set up as a invisible filter.

    Then users could edit all the expressions of one brand only at a time, which is a much nicer UI.

    Does that make sense? Is that possible? I'll have a go throught the code mysely later and report back, but any suggestions welcome.

    Thanks,
    James
      • 3749
      • 24,544 Posts
      Yes, that would probably best be done with a filter like the ones at the top of the System Settings and User grids. You could look at their JS code to see how it's done. Basically, you send just that parameter to the getList processor and it uses it in the query.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 45634
        • 23 Posts
          • 45634
          • 23 Posts
          So if the user types in a search it all works grand.

          But any suggestions on how to make a CMP grid load with a custom search already dialed in from a GET paramater?

          I can add

          Ext.onReady(function() {
              MODx.load({ xtype: 'whisky-page-expression'});
          	
          	var ele = document.getElementById('expressions-search-filter');
          	ele.value="cat";
          	
          });


          Which sets a value in the field, but doesn't trigger a search.

          I also looked at the search function, and it looks as if I could do something like this?

          Ext.onReady(function() {
              MODx.load({ xtype: 'whisky-page-expression'});
          	
          	var ele = document.getElementById('expressions-search-filter');
          	ele.value="cat";
          
                  var grid = Ext.get instanciation of grid JS object here
                  var s = grid.getStore();
                  s.baseParams.query = "cat";
                  grid.getBottomToolbar().changePage(1);
                  grid.refresh();
          	
          });


          I tried several things with Ext.query() but I couldn't work out how to get the right object.

          Thanks for any pointers!
            • 3749
            • 24,544 Posts
            That looks like it should work if you modify the getList processor to use the category, though I'm not sure how you could set a category ahead of time unless you have multiple menu items and inject the category into the JS in the controller.

            It might be easier to load the grid with a default category and let the user select another in a dropdown.
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 45634
              • 23 Posts
              I'm not sure what you mean by Category; is there a special technical meaning of that?

              Basically I have set up a search box and modified the getList processor. This now works fine. If you manually type a value into the search box it works great.

              What I now want is to be able to make that search box prefill with a value I set on page load - any pointers on that?

              Alternatively, if Category is a better way of doing that and you can point me to a resource that shows me how to set that up and how to load the grid with a default category that would be great to - Thanks.
                • 3749
                • 24,544 Posts
                No, I'm using 'category' generically. I was guessing (wrongly) that you wanted to show rows in a certain category.

                Where are the search terms you want to preload coming from?
                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting