Nested columns #96
Replies: 2 comments
-
|
Partially answering my own question… |
Beta Was this translation helpful? Give feedback.
-
|
Hey @leevigraham, thanks for the input, and sorry for the late reply! The I'll create an issue soon for nesting columns, and I am really eager to implement those, as I am also in need of such feature :). I'm thinking of some simple, yet friendly API, similar to forms. Let's assume, that we have to render a table like that: To achieve such hierarchy, I'm thinking on something like this: namespace App\DataTable\Type;
use Kreyu\Bundle\DataTableBundle\Column\Type\ColumnType;
use Kreyu\Bundle\DataTableBundle\Column\Type\NumberColumnType;
use Kreyu\Bundle\DataTableBundle\Column\Type\TextColumnType;
use Kreyu\Bundle\DataTableBundle\Type\AbstractDataTableType;
use Kreyu\Bundle\DataTableBundle\DataTableBuilderInterface;
class ProductDataTableType extends AbstractDataTableType
{
public function buildDataTable(DataTableBuilderInterface $builder, array $options): void
{
$builder
->addColumn('employee', TextColumnType::class)
->addColumn(
$builder->createColumn('quarter', ColumnType::class)
->addColumn('first', NumberColumnType::class)
->addColumn('second', NumberColumnType::class)
)
;
}
}This way, we've created a data table that consists of two columns - employee and quarter, but the latter contains two children columns - respectively first and second. If you create a view of such data table, you should notice two header rows, with appropriate HTML attributes automatically assigned to the first one: /** @var \Kreyu\Bundle\DataTableBundle\DataTableView $view */
$view->headerRows[0]['employee']->vars['attr']; // ['rowspan' => 2]
$view->headerRows[0]['quarter']->vars['attr']; // ['colspan' => 2]This corresponds to the following HTML structure: <thead>
<tr>
<th rowspan="2">Employee</th>
<th colspan="2">Quarter</th>
</tr>
<tr>
<th>I</th>
<th>II</th>
</tr>
</thead>This would require following changes:
$builder
->addColumn('employee', TextColumnType::class)
->addColumn(
$builder->createColumn('quarter', ColumnType::class)
->add('first', NumberColumnType::class) // "add" what?
->add('second', NumberColumnType::class) // "add" what?
)
;
Some breaking changes, but nothing too extreme. Probably needs more changes, but that's how I see it as today. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi @Kreyu ,
Love the idea of using the Form implementation as a basis for a table library. It makes sense to me that form labels could become table headers, and each
tdcell is aDataTableType.If this implementation is based on
FormTypesI assume that means you can have nested types (children). Is that possible in this bundle? I'm not sure how it would render? Nested columns under a singlethwithcolspan.Beta Was this translation helpful? Give feedback.
All reactions