Summary reload after editing item
After editing item there is only 1 row (the edited one) loaded. Summary is then computed from this row only.
Can replicate on example grid https://ublaboo.org/datagrid/.
- hit edit on any row
- then save (no need to change anything)
- look at the summary below
I solved it by setting up summary column inside InlineEdit::$onSubmit. This is not nice solution but works.
SummaryColumn callback running for each row(on inline edit is loaded only one/edited one) so be carefull.
My datasource is Doctrine QueryBuilder, so implement you summary from DB is on you.
<?php
$grid->getInlineEdit()->onSubmit[] = function ($id, ArrayHash $values) use ($grid, $datasource) {
// do some edit ...
$ds = clone $datasource;
$grid->setColumnsSummary(['column'], function ($item, $column) use ($ds) {
$ds->select('SUM(column)');
$ds->setMaxResults(1);
$query = $ds->getQuery();
return $query->getSingleScalarResult();
});
};
Hmm, that is interesting. Could you possibly send a PR?
@paveljanda Who do you said that?
@holantomas Anyone capable of fixing it. Or could anyone possibly send a sandbox-like application with this behaviour for me to test it and fix in using the sandbox app?
@holantomas Thanks for workaround.
I have a facade class for Datagrid. Whenever I update single record I also wanted to redraw only this record including summary. So in my redrawItem method I have this code:
`
$this[$this->gridName]->redrawItem($id);
if (!empty($this->summaryColumns)) {
/** @var QueryBuilder $ds */
$ds = clone $this->dataSource;
$this[$this->gridName]->setColumnsSummary($this->summaryColumns, function ($item, $column) use ($ds) {
$ds->select('SUM(e.' . $column . ')');
$ds->setMaxResults(1);
$query = $ds->getQuery();
return $query->getSingleScalarResult();
});
$this[$this->gridName]->redrawControl('summary');
}
`
Drawbacks of this solution:
- Parent class in datasource must be lableled with "e".
- Does not work if column is not present in database. (calculating online)