Pre set value of filter in list view

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • krishnapriya
    Senior Member
    • Aug 2017
    • 209

    Pre set value of filter in list view

    Hello,

    we have getSelectFilters function to preset search values in link field,

    Same way how to preset search values in list view?

    Please help,

    Thanks.
  • tanya
    Senior Member
    • Jun 2014
    • 4308

    #2
    Hello
    Set in clientDefs "selectDefaultFilters": {"filter": "{name}"}
    application/Espo/Modules/Crm/Resources/metadata/clientDefs/Case.json contains an example

    Comment

    • krishnapriya
      Senior Member
      • Aug 2017
      • 209

      #3
      ok. Thats great. Thanks for your help Tanya.

      Comment

      • krishnapriya
        Senior Member
        • Aug 2017
        • 209

        #4
        This didn't work for me. Is there any way to clear the filter?

        When we goes to another page and comes back to the the page, filter field keeps data which was there before.

        How to clear filter by code?

        Please help
        Thanks.

        Comment

        • tanya
          Senior Member
          • Jun 2014
          • 4308

          #5
          Override list view, method setupSearchManager

          Comment

          • krishnapriya
            Senior Member
            • Aug 2017
            • 209

            #6
            Is there any file using the same code?

            Couldn't make it working.

            Please help.

            Thanks.

            Comment

            • emillod
              Active Community Member
              • Apr 2017
              • 1405

              #7
              tanya can you tell me how to change default filter for search list? For example in task i have field "Customer" which allow me to search parent customer for that task. I can also open list of customers from this field and there i want to setup filter which will show me only customers with status "active". Can you help me?

              Comment

              • nicolar
                Junior Member
                • Dec 2019
                • 11

                #8
                I don't know if anyone has done this at the moment, but if you want to pre set a filter before the result the only way is to override in custom copying the actionList function from the Base class:

                custom/Espo/Custom/Controllers/CustomEntity.php

                PHP Code:
                <?php
                
                namespace Espo\Custom\Controllers;
                
                use Espo\Core\Exceptions\Forbidden;
                
                class CustomEntity extends \Espo\Core\Templates\Controllers\Base
                {
                    /**
                     * Rewrite list action to get only active CustomEntity
                     *
                     * @param $params
                     * @param $data
                     * @param $request
                     *
                     * @return array
                     * @throws Forbidden
                     */
                    public function actionList($params, $data, $request) {
                
                        if (!$this->getAcl()->check($this->name, 'read')) {
                            throw new Forbidden();
                        }
                
                        $params = [];
                        $this->fetchListParamsFromRequest($params, $request, $data);
                
                // START CUSTOM FILTERS
                
                        $params['where'][] = [
                            'attribute' => 'status',
                            'type' => 'in',
                            'value' => ['active']
                        ];
                
                // END CUSTOM FILTERS
                
                        $maxSizeLimit = $this->getConfig()->get('recordListMaxSizeLimit', self::MAX_SIZE_LIMIT);
                        if (empty($params['maxSize'])) {
                            $params['maxSize'] = $maxSizeLimit;
                        }
                        if (!empty($params['maxSize']) && $params['maxSize'] > $maxSizeLimit) {
                            throw new Forbidden("Max size should should not exceed " . $maxSizeLimit . ". Use offset and limit.");
                        }
                
                        $result = $this->getRecordService()->find($params);
                
                        if (is_array($result)) {
                            return [
                                'total' => $result['total'],
                                'list' => isset($result['collection']) ? $result['collection']->getValueMapList() : $result['list']
                            ];
                        }
                
                        return [
                            'total' => $result->total,
                            'list' => isset($result->collection) ? $result->collection->getValueMapList() : $result->list
                        ];
                    }
                }

                This is the best solution you can develop because there aren't methods that allow to add additional filters (or I can't find them searching in Services and in SelectManagers)
                Hope it helps!
                Last edited by nicolar; 04-20-2020, 10:20 AM.

                Comment

                • christdady
                  Junior Member
                  • Apr 2020
                  • 1

                  #9
                  Hello,
                  I hope you're going well.
                  I would like to add serial numbers on invoices in the CRM. I have created a Serial Number entity that contains the product and serial number fields.
                  On the sales order item, I have added a multilink serial number that allows me to select multi serial numbers when I make a sale.
                  I would like to be able to filter on the serial number field so that, when on sales order item, I click on serial number, the serial number entity displays only the serial numbers related to the product choose on sales order item, not all serial numbers in serial number entity.
                  How can I set filter on item list ?

                  Thanks

                  Comment

                  Working...