Editing the cells
We can make the Table editable
with a callback that fires on change.
All cells are assumed editable unless negated in the column definition.
If you switch to verbose syntax, you can also disable editing per row.
You can override both columns and rows by specifying
editable:true
on the individual cells. Again, this would best be done using
verbose syntax.
Multiline editing
You can enter newlines by holding SHIFT on ENTER. You will need to enter two newlines to create a paragraph. Note however that we only show the first paragraph unless the column is set to wrap.
Input validation
Note that the actual update is a manual proces. This will give you a break to validate the input. In this example, we'll show the errors in a Notification.
We can report the errors in a less annoying way if we pass a string as we mark the cells
invalid
. The message will show in the
statubar
when the cell is focused. We'll also initialize the statusbar with an empty string so that
it doesn't awkwardly pop into existance.
When the cell is eventually updated, it automatically becomes valid. Let's talk more about
the difference between text
and value
in the example above.
Text versus value
It doesn't always matter, but it's important to note that we edit the value while we show the text. Here's another example to illustrate the difference.
This way, we can edit, validate and persist the data in a uniform format (in this case, JavaScript numbers) while displaying a regionalized or otherwise customized format. We can exploit this creatively, by editing a document ID and showing the document title, for example. Remember to update verbosely:
— because otherwise the text becomes identical to the value. Also note that the
editable
callback will always serve the value as a string, so it may be
nescessary to convert it to a number. Here's the more complete example.
Here's an overview of the editing related features.
API for knowing when something is invalid / everything is valid.
How to visually differentiate editable versus non-editable cells?