Skip to content

Commit

Permalink
Better error exeption for editable column wrong value
Browse files Browse the repository at this point in the history
Pokud se nastaví sloupec na `editable` a value obsahuje objekt, který nelze konvertovat na string, vrací Grido nic neříkající chybu (např.):

```
Recoverable Error
Object of class DateTime could not be converted to string
```

Po úpravě vrátí:

```
Exception
Column 'date' has error: You must define callback via setEditableValueCallback().
```

Viz: https://forum.nette.org/cs/13109-grido-datagrid-pro-nette?p=19#p164235 a https://forum.nette.org/cs/13109-grido-datagrid-pro-nette?p=19#p164380
  • Loading branch information
Olicek committed Oct 28, 2015
1 parent 8694c95 commit cb9c0b6
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/Components/Columns/Editable.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,28 @@ public function getHeaderPrototype()
* Returns cell prototype (<td> html tag).
* @param mixed $row
* @return \Nette\Utils\Html
* @throws \Exception
*/
public function getCellPrototype($row = NULL)
{
$td = parent::getCellPrototype($row);

if ($this->isEditable() && $row !== NULL) {
$td->data['grido-editable-value'] = $this->editableValueCallback === NULL
$editableValue = $this->editableValueCallback === NULL
? parent::getValue($row)
: callback($this->editableValueCallback)->invokeArgs(array($row, $this));

if ((!is_array( $editableValue)) &&
((!is_object( $editableValue) && settype($editableValue, 'string') !== FALSE) ||
(is_object($editableValue) && method_exists($editableValue, '__toString')))
) {
$td->data['grido-editable-value'] = $editableValue;

} else {
$colName = $this->getColumn();
$msg = "Column '$colName' has error: You must define callback via setEditableValueCallback().";
throw new \Exception($msg);
}
}

return $td;
Expand Down

0 comments on commit cb9c0b6

Please sign in to comment.