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
Add in your module:
sales_order_grid.xml view/adminhtml/ui_component/
<?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">
<columns name="sales_order_columns">
<column name="billing_name" class="VendorName\ModuleName\Ui\Component\Listing\Column\BillTo">
<settings>
<filter>text</filter>
<label translate="true">Bill-to Name</label>
</settings>
</column>
</columns>
</listing>
Now add, BillTo.php in Ui/Component/Listing/Column/BillTo.php
<?php
namespace VendorName\ModuleName\Ui\Component\Listing\Column;
use Magento\Framework\Exception\LocalizedException;
use Magento\Ui\Component\Listing\Columns\Column;
class BillTo extends Column
{
public function prepare()
{
if( //Login role or name is restricted column, here you can verify loggedin admin name or role with condition whatever your need is ) {
$this->_data['config']['componentDisabled'] = true;
}
parent::prepare();
}
}
Best Answer
It's little bit tricky, but i hope this way can help you
app/code/Acme/StackExchange/etc/adminhtml/di.xml
app/code/Acme/StackExchange/Plugin/Ui/Component/Listing/ColumnsControlsPlugin.php