Ublaboo datagrid generování treeview
- jAkErCZ
- Člen | 322
Zdravím všechny,
Snažím se vytvořit datagrid který vygeneruje treeview ale nějak jsem se
zasekl na db.
Presenter kde generuji datagrid
/**
* @param $name
* @throws \Ublaboo\DataGrid\Exception\DataGridColumnStatusException
* @throws \Ublaboo\DataGrid\Exception\DataGridException
*/
public function createComponentReasonGrid($name)
{
$grid = new DataGrid();
$reasons = $this->settignsRepository->getReasonList();
$this->addComponent($grid, $name);
$grid->setPrimaryKey('reason_id');
$grid->setDataSource($reasons);
$grid->setTreeView([$this, 'getChildren'], 'has_children');
$grid->setDefaultSort(['id' => 'ASC']);
$grid->addColumnText('title', 'Název důvodu')
->setSortable()
->setFilterText();
$grid->addColumnNumber('id', 'ID', 'reason_id')
->setFormat(0, '', '')
->setSortable()
->setFilterText();
$grid->addColumnStatus('hidden', 'Stav')
->setAlign('center')
->addOption(0, 'Aktivní')
->setClass('btn-primary')
->endOption()
->addOption(1, 'Neaktivní')
->setClass('btn-success')
->endOption()
->onChange[] = [$this, 'categoriesStatusChange'];
$grid->addAction('create', 'Nová kategorie', '')
->addParameters(['act' => 'new-sub',])
->setIcon('plus')
->setClass('btn btn-xs btn-default')
->setTitle('Nová kategorie');
/**
* Edit Action
*/
$grid->addAction('edit', 'Editace', '')
->setIcon('edit')
->setTitle('Upravit detail kategorie')
->setClass('btn btn-xs btn-success');
/**
* Delete action
*/
$grid->allowRowsAction('delete', function($item) {
return !$this->settignsRepository->checkDeleteReason($item->reason_id);
});
$grid->addAction('delete', '', 'delete!')
->setIcon('trash')
->setTitle('Smazat')
->setClass('btn btn-xs btn-danger ajax')
->setConfirm('Opravdu chcete kategorii ?');
$grid->onRender[] = function (\Ublaboo\DataGrid\DataGrid $grid) use ($reasons): void {
$grid->setDataSource($reasons->getReasonList());
};
}
Db která má vrátit treeview
public function getReasonList() {
$join = $this->db->select('COUNT(reason_id) AS count, parent_reason_id')
->from(self::TABLE_REASON)
->groupBy('parent_reason_id');
$fluent = $this->db
->select('c.*, c_b.count as has_children')
->from(self::TABLE_REASON, 'c')
->leftJoin($join, 'c_b')
->on('c_b.parent_reason_id = c.reason_id')
->where('c.parent_reason_id IS NULL');
return $fluent;
}
public function getChildren($id) {
$join = $this->db->select('COUNT(reason_id) AS count, parent_reason_id')
->from(self::TABLE_REASON)
->groupBy('parent_reason_id');
$fluent = $this->db
->select('c.*, c_b.count as has_children')
->from(self::TABLE_REASON, 'c')
->leftJoin($join, 'c_b')
->on('c_b.parent_reason_id = c.reason_id')
->where('c.parent_reason_id = %i', $id);
return $fluent;
}
DB
DROP TABLE IF EXISTS `reason`;
CREATE TABLE `reason` (
`reason_id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(100) COLLATE utf8_czech_ci NOT NULL,
`order_no` int(11) NOT NULL,
`hidden` tinyint(4) NOT NULL,
`perent_reason_id` int(11) DEFAULT NULL,
PRIMARY KEY (`reason_id`),
KEY `perrent_reason_id` (`perent_reason_id`),
CONSTRAINT `reason_ibfk_1` FOREIGN KEY (`perent_reason_id`) REFERENCES `reason` (`reason_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci;
-- 2020-07-17 10:36:49
Chyba:
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'GET REASON LIST ORDER BY `reason_id` ASC' at line 1
SELECT c.*, c_b.count as has_children
FROM reason c
LEFT JOIN (
SELECT COUNT(reason_id) AS count, parent_reason_id
FROM `reason`
GROUP BY `parent_reason_id`) c_b ON c_b.parent_reason_id = c.reason_id
WHERE c.parent_reason_id IS NULL GET REASON LIST
ORDER BY `reason_id` ASC
Tuto stejnou metodu již používám v jiné aplikaci a tam vše funguje ale na druhé to nechce jet.
Díky všem za pomoc
Editoval jAkErCZ (17. 7. 2020 12:38)
- nightfish
- Člen | 519
jAkErCZ napsal(a):
Chyba:... for the right syntax to use near 'GET REASON LIST ...' ... WHERE c.parent_reason_id IS NULL GET REASON LIST ORDER BY `reason_id` ASC
Podle chybové hlášky máš v dotazu navíc „GET REASON LIST“. V kódu, který jsi poslal, tento řetězec nikde nefiguruje, takže očekávám, že je to nějaká zapomenutý ladicí text. Hledej, najdi, odstraň a třeba to začne zase fungovat.