我使用UI组件在Magento管理员中创建了一个自定义网格。基本上,除了未正确显示的列顺序之外,其他所有程序都工作正常。
- 如您所见,“操作”列位于开头,而选定的列位于结尾
- 当我在XML中创建列时,我考虑了
sortOrder
每一列的属性,但是某种程度上,顺序并不是我将其设置为
来自的代码listing.xml
如下
<columns name="inactive_columns" class="Module\MyModule\Ui\Component\Listing\Columns">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="storageConfig" xsi:type="array">
<item name="provider" xsi:type="string">inactive_listing.inactive_listing.listing_top.bookmarks</item>
<item name="namespace" xsi:type="string">current</item>
</item>
<item name="editorConfig" xsi:type="array">
<item name="selectProvider" xsi:type="string">inactive_listing.inactive_listing.inactive_columns.ids</item>
<item name="enabled" xsi:type="boolean">true</item>
<item name="indexField" xsi:type="string">entity_id</item>
<item name="clientConfig" xsi:type="array">
<item name="saveUrl" xsi:type="url" path="customer/index/inlineEdit"/>
<item name="validateBeforeSave" xsi:type="boolean">false</item>
</item>
</item>
<item name="childDefaults" xsi:type="array">
<item name="fieldAction" xsi:type="array">
<item name="provider" xsi:type="string">inactive_listing.inactive_listing.inactive_columns_editor</item>
<item name="target" xsi:type="string">startEdit</item>
<item name="params" xsi:type="array">
<item name="0" xsi:type="string">${ $.$data.rowIndex }</item>
<item name="1" xsi:type="boolean">true</item>
</item>
</item>
<item name="storageConfig" xsi:type="array">
<item name="provider" xsi:type="string">inactive_listing.inactive_listing.listing_top.bookmarks</item>
<item name="root" xsi:type="string">columns.${ $.index }</item>
<item name="namespace" xsi:type="string">current.${ $.storageConfig.root }</item>
</item>
</item>
</item>
</argument>
<selectionsColumn name="ids">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="indexField" xsi:type="string">entity_id</item>
<item name="sortOrder" xsi:type="number">0</item>
</item>
</argument>
</selectionsColumn>
<column name="entity_id">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">textRange</item>
<item name="sorting" xsi:type="string">asc</item>
<item name="label" xsi:type="string" translate="true">ID</item>
<item name="sortOrder" xsi:type="number">20</item>
</item>
</argument>
</column>
<column name="firstname">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">text</item>
<item name="label" xsi:type="string" translate="true">Firstname</item>
<item name="editor" xsi:type="string">text</item>
<item name="sortOrder" xsi:type="number">40</item>
</item>
</argument>
</column>
<column name="lastname">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">text</item>
<item name="label" xsi:type="string" translate="true">Lastname</item>
<item name="editor" xsi:type="string">text</item>
<item name="sortOrder" xsi:type="number">50</item>
</item>
</argument>
</column>
<column name="email">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">text</item>
<item name="editor" xsi:type="string">text</item>
<item name="label" xsi:type="string" translate="true">Email Cacat</item>
<item name="sortOrder" xsi:type="number">30</item>
</item>
</argument>
</column>
<column name="group_id">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">select</item>
<item name="editor" xsi:type="string">select</item>
<item name="component" xsi:type="string">Magento_Ui/js/grid/columns/select</item>
<item name="dataType" xsi:type="string">select</item>
<item name="label" xsi:type="string" translate="true">Group</item>
<item name="sortOrder" xsi:type="number">90</item>
</item>
</argument>
</column>
<column name="billing_telephone">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">text</item>
<item name="editor" xsi:type="string">text</item>
<item name="label" xsi:type="string" translate="true">Phone</item>
<item name="sortOrder" xsi:type="number">100</item>
</item>
</argument>
</column>
<column name="created_at" class="Magento\Ui\Component\Listing\Columns\Date">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">dateRange</item>
<item name="dataType" xsi:type="string">date</item>
<item name="component" xsi:type="string">Magento_Ui/js/grid/columns/date</item>
<item name="label" xsi:type="string" translate="true">Customer Since</item>
<item name="sortOrder" xsi:type="number">110</item>
</item>
</argument>
</column>
<column name="last_visit_at" class="Magento\Ui\Component\Listing\Columns\Date">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/columns/date</item>
<item name="filter" xsi:type="string">dateRange</item>
<item name="visible" xsi:type="boolean">false</item>
<item name="dataType" xsi:type="string">date</item>
<item name="label" xsi:type="string" translate="true">Last Logged In</item>
<item name="sortOrder" xsi:type="number">120</item>
</item>
</argument>
</column>
<column name="created_in">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="visible" xsi:type="boolean">false</item>
<item name="label" xsi:type="string" translate="true">Account Created in</item>
<item name="sortOrder" xsi:type="number">140</item>
</item>
</argument>
</column>
<column name="kpi_views_customer">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">text</item>
<item name="label" xsi:type="string" translate="true">Kpi Views</item>
<item name="sortOrder" xsi:type="number">60</item>
</item>
</argument>
</column>
<column name="customer_membership">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">text</item>
<item name="label" xsi:type="string" translate="true">Customer Membership</item>
<item name="sortOrder" xsi:type="number">70</item>
</item>
</argument>
</column>
<column name="customer_access">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">text</item>
<item name="label" xsi:type="string" translate="true">Customer Access</item>
<item name="sortOrder" xsi:type="number">80</item>
</item>
</argument>
</column>
<actionsColumn name="actions" class="Magento\Customer\Ui\Component\Listing\Column\Actions">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="indexField" xsi:type="string">entity_id</item>
<item name="sortOrder" xsi:type="number">222</item>
</item>
</argument>
</actionsColumn>
</columns>
并且类Module \ MyModule \ Ui \ Component \ Listing \ Columns是
class Columns extends \Magento\Ui\Component\Listing\Columns
{
/**
* @var \KPIs\CustomerReports\Model\Customer\Attribute\Repository\AttributeRepository $attributeRepository
*/
protected $attributeRepository;
protected $manageAttributes;
/** @var int */
protected $columnSortOrder;
public function __construct(
ContextInterface $context,
ColumnFactory $columnFactory,
AttributeRepository $attributeRepository,
ManageAttributes $manageAttributes,
InlineEditUpdater $inlineEditor,
array $components = [],
array $data = []
)
{
parent::__construct($context, $components, $data);
$this->columnFactory = $columnFactory;
$this->attributeRepository = $attributeRepository;
$this->manageAttributes = $manageAttributes;
$this->inlineEditUpdater = $inlineEditor;
}
public function prepareDataSource(array $dataSource)
{
$customerAccessOptions = $this->attributeRepository->get(CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, "customer_access")->getOptions();
$customerMembershipOptions = $this->attributeRepository->get(CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, "customer_membership")->getOptions();
if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as & $item) {
if (isset($item["customer_access"])) {
$item["customer_access"][0] = $customerAccessOptions[$item["customer_access"][0]]->getLabel();
}
if (isset($item["customer_membership"])) {
$item["customer_membership"] = $customerMembershipOptions[$item["customer_membership"][0]]->getLabel();
}
}
}
return $dataSource;
}
}
- 如您所见,在该类中,我不执行与sortOrder相关的任何操作:),所以它应该是默认行为
- 另外,动作和选择列不能拖放(据我所知)
有谁知道如何从XML或代码中对列进行排序?该操作应该是最后一列,选择应该是第一列。谢谢!:)
2
尝试在网格中拖放列
—
Keyur Shah
我已经尝试过了,它无法与操作和选择列一起使用
—
Dragos