ublaboo/datagrid : redraw sa nevykoná
- majo1
- Člen | 103
Dobrý deň,
mám vytvorený datagrid, kde mením stavy.
Po zmene stavu sa nový stav sa do databázy zapíše, ale grid sa redrawne až pri ďalšej zmene stavu.
V @layout.latte mám includnutý nette.ajax.js , aj sa inicializuje, všetko po jquery.
Dáta ťahám cez v moduli cez dibi query.
presenter:
public function createComponentBreweryGrid($name)
{
$idexhibition = (int)$this->getParameter('idexhibition');
$grid = new DataGrid($this, $name);
$grid->setSortable();
$grid->setSortableHandler('sortBrewery!');
$grid->setDataSource($this->vystavaManager->getAll('brewery', $idexhibition)->fetchAll());
//$grid->addColumnText('exhibition_has_brewery.ord', 'ord');
$grid->addColumnText('brewery.name', 'Pivovar');
$grid->addColumnStatus('exhibition_has_brewery.special', 'Špeciálny hosť?')
->setCaret(FALSE)
->addOption(1, 'áno')
->setIcon('check')
->setClass('ajax btn btn-default btn-fill')
->endOption()
->addOption(0, 'nie')
->setIcon('times')
->setClass('ajax btn btn-default btn-fill')
->endOption()
->onChange[] = [$this, 'changeSpecialBrewery'];
$grid->addColumnStatus('exhibition_has_brewery.enabled', 'Na výstave?')
->setCaret(FALSE)
->addOption(1, 'áno')
->setIcon('check')
->setClass('ajax btn btn-success btn-fill')
->endOption()
->addOption(0, 'nie')
->setIcon('times')
->setClass('ajax btn btn-danger btn-fill')
->endOption()
->onChange[] = [$this, 'changeEnabledBrewery'];
$grid->addExportCsv( 'Csv export', 'zoznam_pivovarov.csv', 'windows-1250')
->setTitle('Zoznam pivovarov');
$grid->setPagination(FALSE);
}
public function changeEnabledBrewery($id, $status)
{
$this->vystavaManager->setGridItem($id, $status, $col='enabled', $type = "brewery", (int)$this->getParameter('idexhibition'));
$status_text = ['vypnutý', 'zapnutý'][$status];
$this->flashMessage("Pivovar je [$status_text].", 'info');
if ($this->isAjax()) {
$this->redrawControl('flashes');
//$this['breweryGrid']->redrawItem($id);
$this['breweryGrid']->reload();
}
}
public function changeSpecialBrewery($id, $status)
{
$this->vystavaManager->setGridItem($id, $status, $col='special', $type = "brewery", (int)$this->getParameter('idexhibition'));
$status_text = ['obyčajný', 'špeciálny'][$status];
$this->flashMessage("Pivovar nastavený ako [$status_text].", 'info');
if ($this->isAjax()) {
$this->redrawControl('flashes');
//$this['breweryGrid']->redrawItem($id);
$this['breweryGrid']->reload();
}
}
Ďakujem za všetky rady.
M.
Editoval majo1 (10. 1. 2018 21:07)
- Ondřej Kubíček
- Člen | 494
tohle je forum ohledně Nette, zkus se zeptat přímo na Gitteru Ublaboo https://gitter.im/ublaboo/help
- David Matějka
- Moderator | 6445
rekl bych, ze to
$grid->setDataSource($this->vystavaManager->getAll('brewery', $idexhibition)->fetchAll());
konkretne to fetchAll nacte vsechna data v tomto okamziku, takze se nebere v potaz pozejsi zmena dat