Hi, I need help with dynamic columns in a DataGrid. I use GenericFrame front-end with PHP backend.
If I use static columns like this:
<? ... ?>
<DataGrid id="DataGrid1" width="100%">
<columns>
<DataGridColumn headerText="name" dataField="@username" width="150"/>
<DataGridColumn headerText="Nahcname" dataField="@secondname" width="150"/>
<DataGridColumn headerText="alter" dataField="@age" width="40"/>
</columns>
</DataGrid>
<? ... ?>
It is working fine.
But I try to create the columns dynamic with PHP.
<generic>
<template target="gridbox">
<VBox id="dynamic" height="100%">
<!-- DataGrid -->
<DataGrid id="DataGrid1" width="100%" >
<columns>
<?php
$columns = array( //Spalte => (Breite, Datenfeld)
"name" => array(150,"@username"),
"Nahcname" => array(150,"@secondname"),
"alter"=> array(40,"@age")
);
foreach ($columns as $key => $value) { ?>
<DataGridColumn headerText="<? echo $key; ?>" dataField="<? echo $value[0]; ?>" width="<? echo $value[0];?>"/>
<?php } ?>
</columns>
</DataGrid>
<Binding source="templatedata.data1.item" destination="DataGrid1.dataProvider" />
</VBox>
</template>
<templatedata>
<data1>
<!-- Daten -->
<item username="User1" secondname="Nachname1" age="22"/>
<item username="User2" secondname="Nachname2" age="25"/>
<item username="User3" secondname="Nachname3" age="27"/>
<item username="User4" secondname="Nachname4" age="32"/>
</data1>
</templatedata>
The DataGrid is displayed correctly, but without data? any idea why?