Announcement

Collapse
No announcement yet.

How to modify or add condition to default 'All' filters

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

  • How to modify or add condition to default 'All' filters

    Hi, everyone!
    Is it possible modify the default filters?
    I need to add condition on the default record list based on the user role without adding another custom filter

    Thank you

  • #2
    Originally posted by newbie View Post
    Hi, everyone!
    Is it possible modify the default filters?
    I need to add condition on the default record list based on the user role without adding another custom filter

    Thank you
    maybe that should be tackled by roles and permissions. you can still of course create you own custom filters but they won't be applied by default.

    Comment


    • newbie
      newbie commented
      Editing a comment
      Hi @rabli, i didn't see it (modifying the default filter) can be done by roles and permissions. Do you have any reference?
      Also is there any reference that you have try to modify/override the default filters via code?

    • rabii
      rabii commented
      Editing a comment
      i didn't mean to modify the default filters using permissions/roles what i meant is that you are able to restrict users from accessing data using roles. but it seems that your need is to to customise the the initial load of the list view to load certain view.

    • newbie
      newbie commented
      Editing a comment
      ah i see, i just got your point.
      but yes i still need customize the initial load of the list view

  • #3
    Not possible using GUI, you would have to log in each person to manually! create one for them. Sadly there is no easy way and I don't see any near future Yuri will agree to add it either.

    You must use code! Luckily there is a tutorial (video) for this if you wish to delve into this world.
    Last edited by espcrm; 04-02-2023, 06:23 AM.

    Comment


    • #4
      Originally posted by espcrm View Post
      Not possible using GUI, you would have to log in each person to manually! create one for them. Sadly there is easy way and I don't see any near future Yuri will agree to add it either.

      You must use code! Luckily there is a tutorial (video) for this if you wish to delve into this world.
      Hi espcrm, could you please share any tutorial link that related to customize the initial load of the list view?

      Comment


      • #5
        If i remember there was something mentioned in documentation about specifying filters on initial load check this out https://docs.espocrm.com/development...aultfilterdata i think could be done like below :

        custom/Espo/Custom/Resources/metadata/clientDefs/YourEntityType.json


        Primary filter. 'active' is the name of primary filter (dropdown on the left).​

        PHP Code:
        {
            
        "defaultFilterData": {
                
        "primary""active"
             
        }
        }
        ​ 

        Comment


        • #6
          Originally posted by newbie View Post

          Hi espcrm, could you please share any tutorial link that related to customize the initial load of the list view?
          You can find many great guide here, search for filter:

          Comment


          • #7
            Thank you for your help guys,

            After a few days, i ended up to one temporary alternative solution (not recommended).

            In case someone here needs the same custom, this is what i have done (dwyor)

            1. create custom file filter (YourFilter.php) in ../custom/Espo/Custom/Classes/Select/YourEntity/PrimaryFilters
            Code:
            <?php
            
            namespace Espo\Custom\Classes\Select\YourEntity\PrimaryFilters;
            
            ...
            
            class YourFilter implements Filter
            {
            
                private $user;
            
                public function __construct(
                    User $user,
                    private EntityManager $entityManager
                ) {
            
                }
            
                public function apply(SelectBuilder $queryBuilder): void
                {
                    // your logic here
                }
            }​
            2. create custom file map (YourEntity.json) in ../custom/Espo/Custom/Resources/metadata/selectDefs
            Code:
            {
                "primaryFilterClassNameMap": {
                    "Authorized": "Espo\\Custom\\Classes\\Select\\YourEntity\\PrimaryFilters\\YourFilter"
                }
            }​
            3. define your default filter in ../custom/Espo/Custom/Resources/metadata/clientDefs
            Code:
            {
                "filterList": [
                    {
                        "name": "YourFilter"
                    }
                ],
                "defaultFilterData": {
                    "primary": "YourFilter"
                },
                "selectDefaultFilters": {
                    "filter": "YourFilter"
                }
            }​
            4. commenting out or hide the preset filter 'all' in search.tpl script (this last part is not recommended)

            Comment


            • #8
              Hi,

              here is a way to implement your changes without having to touch the core scripts, which will keep the functionality "upgrade safe":

              1) Create a custom template client/custom/res/templates/record/search.tpl incorporating your changes.

              2) Create a custom view class that calls the new template.
              client/custom/src//views/record/search.js
              Code:
              define('custom:views/record/search', 'views/record/search', function (Dep) {
              
                  return Dep.extend({​
              
                      template: custom:record/search,
              
                  });
              
              });
              3) Create a custom view class that calls the custom record search view class
              client/custom/src/views/list.js​​
              Code:
              define('custom:views/list', 'views/list', function (Dep) {
              
                  return Dep.extend({​
              
                      searchView: custom:views/record/search,
              
                  });
              
              });

              4) Call the custom list view class in your entity's metadata clientDefs
              Code:
              {
                  "views": {
                      "list": "custom:views/list"
                  }
              }

              Comment


              • #9
                Originally posted by telecastg View Post
                Hi,

                here is a way to implement your changes without having to touch the core scripts, which will keep the functionality "upgrade safe":

                1) Create a custom template client/custom/res/templates/record/search.tpl incorporating your changes.

                2) Create a custom view class that calls the new template.
                client/custom/src//views/record/search.js
                Code:
                define('custom:views/record/search', 'views/record/search', function (Dep) {
                
                return Dep.extend({​
                
                template: custom:record/search,
                
                });
                
                });
                3) Create a custom view class that calls the custom record search view class
                client/custom/src/views/list.js​​
                Code:
                define('custom:views/list', 'views/list', function (Dep) {
                
                return Dep.extend({​
                
                searchView: custom:views/record/search,
                
                });
                
                });

                4) Call the custom list view class in your entity's metadata clientDefs
                Code:
                {
                "views": {
                "list": "custom:views/list"
                }
                }
                this is awesome, thanks for sharing telecastg

                Comment


                • telecastg
                  telecastg commented
                  Editing a comment
                  You're very welcome
              Working...
              X