Magento – Updating ui_bookmark Table When Adding Columns via ui_component XML

magento2uicomponentxml

In Magento 2, the ui_component based grids allow you to reorder columns and Magento will remember your settings the next time you log in. This is accomplished by Magento saving data in the ui_bookmark table (via a Magento\Ui\Model\Bookmark model object).

While this feature it neat, it can create problems when a extension developer or system integrator uses Magento ui_component XML to add columns to a table. If there's a custom data ui_bookmark then Magento will (seemingly) ignore the sort order of a new column and weird/unexpected things can happen.

Is there a best practice and/or system for extension developers who want to add columns to a UI Grid (either Magento's or their own) and ensure a column is somewhere in relation to the others? i.e. — "This second action button should always appear last, or always appear second last", or "the name field should always be after ID.

Does an extension developer need to, via an app/code/Package/Module/Setup/... class, reach into the ui_bookmark table and update these entries themselves? Or is there a better way to accomplish this? Or do extension developers just need to live with a column being added to unexpected places when a user already has an entry in ui_bookmark?

Best Answer

I think that this is bug in magento2.

I usually clean ui_bookmark table after adding new columns by any modules.

Magento2 save columns positions even if there are no any modification in columns ordering.

"positions":{
    "ids":0,
    "increment_id":1,
    "store_id":2,
    "created_at":3,
    "billing_name":4,
    "shipping_name":5,
    ...
}

But if columns positions will be stored only after user modifications, we will have same problem with new columns.

If will be added relative ordering like as name column after id or my_column before actions, we will have ugly dragging of columns in UI.

If you will clear ui_bookmark table during module installation - you can clear custom user settings for the listing.

Maybe, core developers need to fix actions column as last as partial solution.

I think, that this question has not the only right decision

Related Topic