嗯,从你想要显示related items
(订单产品)under the
订单记录的问题中,它自己,
使用扩展似乎是不可能的,或者如果我们使用那个东西可能会变得更加困难/复杂
相反,我们可以使用small trick
我们将override partial
针对list
该特定列表,为此我们可以使用它的config_list.yaml
使用该order
列表配置添加此附加选项
....
toolbar:
buttons: list_toolbar
search:
prompt: 'backend::lang.list.search_prompt'
recordUrl: 'hardiksatasiya/demotest/demo/update/:id'
// add customViewPath
customViewPath: $/hardiksatasiya/demotest/controllers/demo/list_override
现在在这里我们覆盖 2 个部分(我已经从 复制它们modules\backend\widgets\lists\partials
)
_list_body_rows.htm
_list_body_row.htm
我修改那里的内容
_list_body_rows.htm
<?php foreach ($records as $record): ?>
<?= $this->makePartial('list_body_row', [
'record' => $record,
'treeLevel' => $treeLevel,
'custom' => isset($custom) ? true : false])
?>
<?php endforeach ?>
_list_body_row.htm
<?php
$expanded = $showTree ? $this->isTreeNodeExpanded($record) : null;
$childRecords = $showTree ? $record->getChildren() : null;
$treeLevelClass = $showTree ? 'list-tree-level-'.$treeLevel : '';
?>
<tr class="<?= $treeLevelClass ?> <?= $this->getRowClass($record) ?>">
<!-- we are using that custom variable here we dont want to show check box for our products-->
<?php if ($showCheckboxes && $custom == false): ?>
<?= $this->makePartial('list_body_checkbox', ['record' => $record]) ?>
<?php endif ?>
<?php if ($showTree): ?>
<?= $this->makePartial('list_body_tree', [
'record' => $record,
'expanded' => $expanded,
'childCount' => $record->getChildCount()
]) ?>
<?php endif ?>
<!-- we are using that custom variable here
and make our row seperatly as we need
for all item/product record this partial executed so
we code it for single row it will be repeated through all product items automatically-->
<?php if($custom): ?>
<td> <!-- checkbox column we make it blank--> </td>
<!--
colspan based on requirement
you can fully customize your td tags from here
-->
<td colspan="<?= count($columns) ?>"> <a href="/backend/products/edit/<?= $record->id ?>"> <?= $record->name ?> </a></td>
<?php else: ?>
<?php $index = $url = 0; foreach ($columns as $key => $column): ?>
<?php $index++; ?>
<td class="list-cell-index-<?= $index ?> list-cell-name-<?= $column->getName() ?> list-cell-type-<?= $column->type ?> <?= $column->clickable ? '' : 'nolink' ?> <?= $column->cssClass ?>">
<?php if ($column->clickable && !$url && ($url = $this->getRecordUrl($record))): ?>
<a <?= $this->getRecordOnClick($record) ?> href="<?= $url ?>">
<?= $this->getColumnValue($record, $column) ?>
</a>
<?php else: ?>
<?= $this->getColumnValue($record, $column) ?>
<?php endif ?>
</td>
<?php endforeach ?>
<?php endif; ?>
<?php if ($showSetup): ?>
<td class="list-setup"> </td>
<?php endif ?>
</tr>
<?php if ($showTree && $expanded): ?>
<?= $this->makePartial('list_body_rows', ['records' => $childRecords, 'treeLevel' => $treeLevel+1]) ?>
<?php endif ?>
<!-- you can customise this condition basde on your order have items or not
i used simple relation condition here -->
<?php if ($record->relation): ?>
<?php $childRecords = is_array($record->relation) ? $record->relation : [$record->relation]; ?>
<?php
// currently as $childRecords i used relation but you can create your own model array
// and pass here it will be received in next iteration
// notice we are passing $custom variable and we also override
// _list_body_rows.htm and it will loop through all records and pass
// $custom variable and it will be true based on its existance
// if we pass custom variable it will pass it also with true other wise
// it will pass it false
?>
<?= $this->makePartial('list_body_rows', ['records' => $childRecords, 'treeLevel' => $treeLevel+1, 'custom' => true]) ?>
<?php endif ?>
它会给你这样的输出
added comments
如果您需要 mroe 信息,我也new paritals
知道如何使用它们,请发表评论。