0

I created listing using UI Component in frontend. I also created custom bookmark for saving the state of the UI Component because I want store it as a customer, because the default bookmark only save state of admin user.

UI Component XML

<?xml version="1.0" encoding="UTF-8"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <argument name="data" xsi:type="array">
        <item name="js_config" xsi:type="array">
            <item name="provider" xsi:type="string">rendyep_orderexport_log_listing.rendyep_orderexport_log_listing_data_source</item>
        </item>
    </argument>
    <settings>
        <spinner>rendyep_orderexport_log_columns</spinner>
        <deps>
            <dep>rendyep_orderexport_log_listing.rendyep_orderexport_log_listing_data_source</dep>
        </deps>
    </settings>
    <dataSource name="rendyep_orderexport_log_listing_data_source" component="Magento_Ui/js/grid/provider">
        <settings>
            <storageConfig>
                <param name="indexField" xsi:type="string">log_id</param>
            </storageConfig>
            <updateUrl path="mui/index/render"/>
        </settings>
        <dataProvider class="Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider" name="rendyep_orderexport_log_listing_data_source">
            <settings>
                <requestFieldName>id</requestFieldName>
                <primaryFieldName>log_id</primaryFieldName>
            </settings>
        </dataProvider>
    </dataSource>
    <listingToolbar name="listing_top">
        <bookmark name="bookmarks">
            <settings>
                <storageConfig>
                    <param name="saveUrl" xsi:type="url" path="rendyep/bookmark/save"/>
                    <param name="deleteUrl" xsi:type="url" path="rendyep/bookmark/delete"/>
                </storageConfig>
            </settings>
        </bookmark>
        <columnsControls name="columns_controls"/>
        <filters name="listing_filters"/>
        <paging name="listing_paging"/>
    </listingToolbar>
    <columns name="rendyep_orderexport_log_columns">
        <selectionsColumn name="ids">
            <settings>
                <indexField>log_id</indexField>
            </settings>
        </selectionsColumn>
        <column name="log_id" sortOrder="10">
            <settings>
                <filter>textRange</filter>
                <label translate="true">Log ID</label>
            </settings>
        </column>
        ....
        <column name="profile_id" component="Magento_Ui/js/grid/columns/select" sortOrder="40">
            <settings>
                <dataType>select</dataType>
                <filter>select</filter>
                <options class="Rendyep\OrderExport\Ui\Component\Listing\Options\OrderExport\Log\Profiles"/>
                <label translate="true">Profile</label>
            </settings>
        </column>
        ....

Custom bookmark table & related things

Basically the custom bookmark table, model, controller that handle the save and delete, and all PHP classes related to it (BookmarkManagement, BookmarkRepository, etc) is the same as the default bookmark, except that the user_id field is linked to customer_entity instead of admin_user. The data is also stored successfully in database when the listing requested data update using the custom saveUrl: https://domain.com/rendyep/bookmark/save/

# bookmark_id   user_id namespace   identifier  current title   config  created_at  updated_at
14  15  rendyep_orderexport_log_listing current 0       {"current":{"filters":{"applied":{"placeholder":true,"profile_id":"2"}},"displayMode":"grid","columns":{"log_id":{"visible":true,"sorting":false},"files":{"visible":true,"sorting":false},"records_exported":{"visible":true,"sorting":false},"result":{"visible":true,"sorting":false},"result_message":{"visible":true,"sorting":false},"ids":{"visible":true,"sorting":false},"export_type":{"visible":true,"sorting":false},"entity":{"visible":true,"sorting":false},"profile_id":{"visible":true,"sorting":false},"created_at":{"visible":true,"sorting":false},"manual_export":{"visible":true,"sorting":false}},"paging":{"options":{"20":{"value":20,"label":20},"30":{"value":30,"label":30},"50":{"value":50,"label":50},"100":{"value":100,"label":100},"200":{"value":200,"label":200}},"value":30},"positions":{"ids":0,"log_id":1,"export_type":2,"entity":3,"profile_id":4,"files":5,"records_exported":6,"result":7,"result_message":8,"created_at":9,"manual_export":10}}}   0000-00-00 00:00:00 0000-00-00 00:00:00
15  15  rendyep_orderexport_log_listing default 1   Default View    {"views":{"default":{"label":"Default View","index":"default","editable":false,"data":{"filters":{"applied":{"placeholder":true}},"displayMode":"grid","columns":{"log_id":{"visible":true,"sorting":false},"files":{"visible":true,"sorting":false},"records_exported":{"visible":true,"sorting":false},"result":{"visible":true,"sorting":false},"result_message":{"visible":true,"sorting":false},"ids":{"visible":true,"sorting":false},"export_type":{"visible":true,"sorting":false},"entity":{"visible":true,"sorting":false},"profile_id":{"visible":true,"sorting":false},"created_at":{"visible":true,"sorting":false},"manual_export":{"visible":true,"sorting":false}},"paging":{"options":{"20":{"value":20,"label":20},"30":{"value":30,"label":30},"50":{"value":50,"label":50},"100":{"value":100,"label":100},"200":{"value":200,"label":200}},"value":20},"positions":{"ids":0,"log_id":1,"export_type":2,"entity":3,"profile_id":4,"files":5,"records_exported":6,"result":7,"result_message":8,"created_at":9,"manual_export":10}},"value":"Default View"}}}    0000-00-00 00:00:00 0000-00-00 00:00:00

The Issue

After applying any filter(s), the custom bookmark data is updated successfully in database. But when I reload the listing page, the filter is gone and is not populated, and the custom bookmark data is reset to its original state without any filters in it.

Is there a way to populate the filters using the last saved ones in custom bookmark data upon reloading the listing page?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.