datagrid icon indicating copy to clipboard operation
datagrid copied to clipboard

Summary reload after editing item

Open vitkutny opened this issue 8 years ago • 5 comments

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/.

  1. hit edit on any row
  2. then save (no need to change anything)
  3. look at the summary below

vitkutny avatar Sep 25 '17 14:09 vitkutny

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();
	});
};

holantomas avatar Jun 29 '18 09:06 holantomas

Hmm, that is interesting. Could you possibly send a PR?

paveljanda avatar Oct 05 '18 16:10 paveljanda

@paveljanda Who do you said that?

holantomas avatar Oct 06 '18 18:10 holantomas

@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?

paveljanda avatar Oct 06 '18 19:10 paveljanda

@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)

Jigsik avatar Nov 20 '19 15:11 Jigsik