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 또는 코드에서 열을 정렬하는 방법을 알고 있습니까? 작업은 마지막 열이고 선택은 첫 번째 열이어야합니다. 감사! :)