Hello Friends!!!
In this blog, we are going to learn how we can add a custom column filter to the sales shipment grid collection.
Here, to customize the sales shipment grid collection, please follow the below steps:
1. Create di.xml inside the app/code/Vendor/Module/etc/ directory. And add the following plugin in your di.xml file.
1 2 3 4 5 6 7 8 |
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory"> <plugin name="Vendor_Module::aroundGetReport" type="Vendor\Module\Plugin\Framework\View\Element\UiComponent\DataProvider\CollectionFactory" sortOrder="1"/> </type> </config> |
2. Create plugin class file CollectionFactory.php inside the app/code/Vendor/Module/Plugin/Framework/View/Element/UiComponent/DataProvider/ directory.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
<?php /** * Vendor Desc. * * @category Vendor Category * @package Vendor_Module * @author Vendor name * @copyright Copyright (c) Vendor (https://example.com) * @license https://example.com/license.html */ namespace Vendor\Module\Plugin\Framework\View\Element\UiComponent\DataProvider; use Magento\Framework\Data\Collection; use Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory as OrigFactory; /** * Class CollectionFactory */ class CollectionFactory { /** * Const SALES_ORDER_SHIPMENT_GRID_DATA_SOURCE: contains source name */ const SALES_ORDER_SHIPMENT_GRID_DATA_SOURCE = 'sales_order_shipment_grid_data_source'; /** * @var Collection[] */ protected $collections; /** * @param array $collections */ public function __construct( array $collections = [] ) { $this->collections = $collections; } /** * Get report collection * * @param OrigFactory $subject * @param \Closure $proceed * @param string $requestName * * @return Collection * @throws \Exception */ public function aroundGetReport( OrigFactory $subject, \Closure $proceed, $requestName ) { $result = $proceed($requestName); $userId = 2; if ($requestName == self::SALES_ORDER_SHIPMENT_GRID_DATA_SOURCE) { //here user_id is custom column of sales_shipment and sales_shipment_grid tables $result->addFieldToFilter("main_table.user_id", $userId); } return $result; } } |
After executing the compilation command, You can see the result in the sales shipment grid.

Hope this will be helpful.
Thanks 🙂
Be the first to comment.