Answer the question
In order to leave comments, you need to log in
Displaying a table as a tree?
I have a table that looks like this
<?php Pjax::begin(); ?>
<?= GridView::widget([
'filterUrl' => Url::toRoute('index'),
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
[
'attribute'=>'company_types__alias',
'label'=> $Package->t('', 'Тип'),
'format'=>'text',
'content'=>function($data){
if ($data->type != null)
return $data->type->title;
},
'filter' => CompanyTypes::getList()
],
'alias',
'name',
'email',
'phone',
[
'class' => 'yii\grid\ActionColumn',
'template' => '{view} {update} '
],
],
]); ?>
<?php Pjax::end(); ?>
<ul id="tree">
<li>
<table>
<thead>
<th>Column</th>
<th>Column1</th>
<th>Column2</th>
<th>Column3</th>
</thead>
<tbody>
<tr>
<td>cell 1</td>
<td>cell 2</td>
<td>cell 3</td>
<td>cell 4</td>
</tr>
</tbody>
</table>
<ul>
<li>
<table>
<tbody>
<tr>
<td>cell 1</td>
<td>cell 2</td>
<td>cell 3</td>
<td>cell 4</td>
</tr>
</tbody>
</table>
<ul>
<li>
<table>
<tbody>
<tr>
<td>cell 1</td>
<td>cell 2</td>
<td>cell 3</td>
<td>cell 4</td>
</tr>
</tbody>
</table>
<ul>
<li>
<table>
<tbody>
<tr>
<td>cell 1</td>
<td>cell 2</td>
<td>cell 3</td>
<td>cell 4</td>
</tr>
</tbody>
</table>
<ul>
<li>
<table>
<tbody>
<tr>
<td>cell 1</td>
<td>cell 2</td>
<td>cell 3</td>
<td>cell 4</td>
</tr>
</tbody>
</table>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
Answer the question
In order to leave comments, you need to log in
And how do you think GRID should learn about descendants?
In fact, everything is simple. You just need to inherit from grid and rewrite the display functions as you need. With a preliminary breakdown into parents and descendants, followed by a recursive output.
Write your dataProvider and your widget for output. Perhaps it's worth not to force the gridview, but the listView?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question