protected function performDataBinding($data)
{
$this->reset();
$keys = $this->getDataKeys();
$keys->clear();
$keyField = $this->getDataKeyField();
// get all columns
if ($this->getAutoGenerateColumns()) {
$columns = new TList($this->getColumns());
$autoColumns = $this->createAutoColumns($data);
$columns->mergeWith($autoColumns);
} else {
$columns = $this->getColumns();
}
$this->_allColumns = $columns;
$items = $this->getItems();
$index = 0;
$allowPaging = $this->getAllowPaging() && $data instanceof TPagedDataSource;
$dsIndex = $allowPaging ? $data->getFirstIndexInPage() : 0;
$this->setViewState('DataSourceIndex', $dsIndex, 0);
if ($columns->getCount()) {
foreach ($columns as $column) {
$column->initialize();
}
$selectedIndex = $this->getSelectedItemIndex();
$editIndex = $this->getEditItemIndex();
foreach ($data as $key => $row) {
if ($keyField !== '') {
$keys->add($this->getDataFieldValue($row, $keyField));
} else {
$keys->add($key);
}
if ($index === 0) {
if ($allowPaging) {
$this->_topPager = $this->createPager();
}
$this->_header = $this->createItemInternal(-1, -1, TListItemType::Header, true, null, $columns);
}
if ($index === $editIndex) {
$itemType = TListItemType::EditItem;
} else {
if ($index === $selectedIndex) {
$itemType = TListItemType::SelectedItem;
} else {
if ($index % 2) {
$itemType = TListItemType::AlternatingItem;
} else {
$itemType = TListItemType::Item;
}
}
}
$items->add($this->createItemInternal($index, $dsIndex, $itemType, true, $row, $columns));
$index++;
$dsIndex++;
}
if ($index > 0) {
$this->_footer = $this->createItemInternal(-1, -1, TListItemType::Footer, true, null, $columns);
if ($allowPaging) {
$this->_bottomPager = $this->createPager();
}
}
}
$this->setViewState('ItemCount', $index, 0);
if (!$dsIndex && $this->_emptyTemplate !== null) {
$this->_useEmptyTemplate = true;
$this->_emptyTemplate->instantiateIn($this);
$this->dataBindChildren();
}
}