dynamic Grid columns

Posted by stck777 on Stack Overflow See other posts from Stack Overflow or by stck777
Published on 2010-03-11T21:37:13Z Indexed on 2010/03/11 21:39 UTC
Read the original article Hit count: 282

Filed under:

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?

© Stack Overflow or respective owner

Related posts about php