Hello,
I’m rewriting Yii v1 application to v2 and I want to create dynamic list of columns for Gridview.
I don’t know exactly columns before I get data, but I need to format column values. In Yii v1 it was really easy:
foreach ($years as $year)
{
$this->columns[] = array(
'name'=>'m'.$year,
'value'=>'number_format($data[\'m'.$year.'\'], 0, ",", ".")',
);
}
But in v2 I don’t know how to pass $year value inside formatting function
foreach ($years as $year) {
$this->columns[] = [
//if I leave just attribute, everything works, but without formatting
'attribute' => $year,
// we want to use intl formatting with new versions, of course <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/smile.gif' class='bbc_emoticon' alt=':)' />
'value' => function ($data) {
$fmt = new \NumberFormatter('lt_LT', \NumberFormatter::DECIMAL);
return $fmt->format($data[???REPLACE_WITH_YEAR_VALUE???]);
},
];
}
Data for Gridview is from SqlDataProvider.
I really missing documentation and examples for one of most powerful component that I used in Yii v1 - CGridView. Datacolumns, rows selection, JS (afterUpdate, selectionChanged) is completely different from v1 and docs how to upgrade is very welcomed.
Thanks