APYDataGridBundle icon indicating copy to clipboard operation
APYDataGridBundle copied to clipboard

manipulateRenderCell returns wrong entity via $row->getEntity()

Open Bubelbub opened this issue 8 years ago • 4 comments

Hey guys,

I have a small problem which seems to be working in 2013. https://github.com/APY/APYDataGridBundle/issues/391#issuecomment-16038709

	$priceColumn = new BlankColumn(array('id' => 'price', 'title' => 'Price'));
	$priceColumn->setSafe(false)->manipulateRenderCell(
		function($value, $row, $router) {
			/** @var string $value */
			/** @var \APY\DataGridBundle\Grid\Row $row */
			/** @var \AppBundle\Routing\Router $router */
			/** @var Order $order */
			$order = $row->getEntity();

			return $row->getEntity()->getId();
		}
	);
	$grid->addColumn($priceColumn);

This example above returns always the number 3. But expected is 1, 2, 3, 4, 5, 6, 7, ...

And this returns correct key.

	$priceColumn = new BlankColumn(array('id' => 'price', 'title' => 'Price'));
	$priceColumn->setSafe(false)->manipulateRenderCell(
		function($value, $row, $router) {
			/** @var string $value */
			/** @var \APY\DataGridBundle\Grid\Row $row */
			/** @var \AppBundle\Routing\Router $router */
			/** @var Order $order */
			$order = $row->getEntity();

			return implode(', ', $row->getPrimaryKeyValue());
		}
	);
	$grid->addColumn($priceColumn);

This returns correct id of entity.

But is this intention or a bug? Because $row->getEntity() is the entity for the row in my understanding 👍

Maybe someone can fix this 👍 Thanks.

Bubelbub avatar Mar 16 '17 11:03 Bubelbub

Thanks for reporting. We should investigate this /cc @hmert

DonCallisto avatar Mar 16 '17 11:03 DonCallisto

Ah maybe the issue is because my entity has this annotation.

* @GRID\Source(columns="orderIdentifier, state, pickupDate", filterable=false)

I found out that:

$row->getPrimaryFieldValue();

Returns always the orderIdentifier - but each time this is different. So thats working.

return implode('', $row->getPrimaryKeyValue());

Returns the order identifier, too.

But I have an ID field. But this is hidden for the customer ;-)

I tried to work around this via:

$order = $orderRepository->find($row->getPrimaryFieldValue());

But this always return the same, too. So I don't know if this is a bundle bug or a problem because I havent the id in the grid columns. But orderIdentifier is unique, too. So if I change the workaround to this it works.

$order = $orderRepository->findByOrderIdentifier($row->getPrimaryFieldValue());

👍

Maybe this helps to clarify this.

Bubelbub avatar Mar 16 '17 12:03 Bubelbub

Ok problem seems to be solved if I add the id column to grid and visible=false to property.

/**
 * @GRID\Source(columns="id, orderIdentifier, state, pickupDate", filterable=false)
 */
class Order
{
	/**
	 * @var int
	 *
	 * @ORM\Column(name="id", type="integer")
	 * @ORM\Id
	 * @ORM\GeneratedValue(strategy="AUTO")
	 *
	 * @GRID\Column(visible=false)
	 */
	private $id;
}

But then it is a bug I think. But the workaround is much better than before 👍

Bubelbub avatar Mar 16 '17 16:03 Bubelbub

@Bubelbub it's not a bug, a design decision actually. We will solve near future.

hmert avatar Mar 17 '17 03:03 hmert