contributte / contributte/datagrid

setEditableValueCallback and second editing

Open
#948 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
296
Forks
215
PR merge metrics
No merged PRs in 30d

Description

I am using something like

$email = $grid->addColumnText( 'email', 'E-mail' )
              ->setRenderer( function ( $item ) {  return $item->email;  } );

$email->setEditableValueCallback( function ( $item ): string { return $item->email; } );

$email->setEditableCallback( function ( $id, $value ) use ( $orm ): string {
	$item = $orm->repo->getById( $id );
	if ( isset( $item ) ) {
		$item->email = $value;
		$orm->repo->persistAndFlush( $item );
		return Html::el( 'a' )->href( 'mailto:' . $item->email )->setText( $item->email )->render();
	}

	return '';
} );

which works perfectly with inline editing, but only for first time in same grid. When I try edit the email field for second time, I get the original value BEFORE the first editing.

That means (what I can see), that setEditableValueCallback is storing data in attribute "datagrid-editable-value", but after setEditableCallback is performed and AJAX returns new value to display, setEditableValueCallback is not called second time and attribute "datagrid-editable-value" is not changed for later modifications.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing setEditableValueCallback and setEditableCallback through the inline-editing AJAX flow, focusing on the datagrid-editable-value attribute described in the report. Reproduce editing the same email field twice and verify that the second edit uses the value returned by the first update.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.