Announcement

Collapse
No announcement yet.

Show field filter on view by default

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Show field filter on view by default

    Hi Devs,

    I want to show a particular field filter by default on a custom modal that I've written. I think it's pretty much the same functionality that is in the Opportunity view where it's showing Close Date by default:

    Click image for larger version

Name:	image.png
Views:	105
Size:	29.3 KB
ID:	100824

    I've searched the code base and googled and I can't find how it's doing it. Can anyone please help?

    Cheers,
    Clare

  • #2
    This link will help: https://forum.espocrm.com/forum/feat...tity#post92689

    Comment


    • #3
      Thanks for the response Victor, but I don't have access to report filters in my Administration screen.

      I figured out how to do this though. Here it is for anyone who needs it.

      I didn't realise initially but Espo is showing that filter because I added it from the 'Add Field' dropdown and Espo is remembering and showing it again when I come back to the screen (not by default which I thought at first). It sets the config for the filters to show in EspoCRM-7.5.5/client/src/views/record/search.js in the updateSearch function:

      Code:
      updateSearch: function () {
          console.log('search.js updatesearch ', this.advanced); // <-- put in some debugging so you can see the format for the filter you want to show - call the filter on another screen
          this.searchManager.set({
            textFilter: this.textFilter,
            advanced: this.advanced, // <-- this is the config data for the filter
            bool: this.bool,
            presetName: this.presetName,
            primary: this.primary,
      });
      console.log('search.js after updatesearch ', this.searchManager);
      },
      ​
      Add the filter you want to show in Entity Manager > Layout > Search Filters. My resulting EspoCRM-7.5.5/custom/Espo/Custom/Resources/layouts/Lens/filters.json file:

      Code:
      [
          "camera1"
      ]​
      In a modal, which is how I'm using it, search.js is called from loadSearch in EspoCRM-7.5.5/client/src/views/modals/select-records.js, so extend this view and alter the loadSearch function. I've directly set the this.filters value - idk if this is best practice but it works - before calling the loadSearch function in select-records.js:

      Code:
      define('custom:extend-select', ['views/modals/select-records'], function (Dep, List) {
          return Dep.extend({
              className: 'dialog dialog-record',
      
              // if true, clicking on the backdrop will close the dialog
              backdrop: true, // 'static', true, false
      
              data: function () {
                  console.log('in data extend-select');
                  var data = Dep.prototype.data.call(this);
                  return data;
              },
      
              loadSearch: function () {
                  this.filters = { // <-- set filter here
                      camera1: {
                          data: { type: 'isEmpty' },
                          type: 'isNotLinked'
                      }
                  };
      
                  Dep.prototype.loadSearch.call(this);
                  console.log('loadSearch ', this.searchManager);
              },
      
              setup: function () {
                  console.log('in setup extend-select ', this);
                  Dep.prototype.setup.call(this);
              },
      
              loadList: function () {
                  Dep.prototype.loadList.call(this);
                  console.log('load list - this is ', this);
                  this.stopListening(this, 'select'); // <-- doesn't work :(
              },
      
          });
      });
      ​

      Comment

      Working...
      X