Stepper editor
cellEditor: 'stepper' adds increase and decrease buttons to a number input. It suits values changed one notch at a time, such as a quantity or a level. You can still type a number, or change it with the buttons or the arrow keys.
{ id: 'qty', kind: 'number', editable: true, cellEditor: 'stepper',
editorParams: { step: 1, min: 0, max: 99 } }It needs the optional editors bundle (maxgrid/editors in the modular build). Without the bundle, creating the grid fails with invalid-option. The number input rules from Cell editing (decimals and the others) work as usual.
Options
All go in editorParams. Defaults apply when omitted.
| Option | Value | Default | Effect |
|---|---|---|---|
step | number greater than 0 | 1 | Size of one step |
min | number | none | Smallest value; buttons and keys stop here |
max | number | none | Largest value; a max below min is an invalid-option |
repeat | 0 or integer 30-500 (ms) | 80 | Repeat interval while a button is held; 0 means no repeat |
layout | 'sides' · 'stacked' | 'sides' | sides is − input +, stacked puts ▲▼ at the right of the input |
typing | boolean | true | false makes the input read-only; only the buttons and keys change it |
decimals | integer 0-10 | none | Decimal places of the result; without it, the larger of step and the value |
The shared input attributes (inputMode, align, placeholder) work as well. An unknown key or a wrong value is an invalid-option when the grid is created (for example step: 0).
Keyboard and buttons
| Input | Effect |
|---|---|
| ↑ · ↓ | Increase or decrease by step |
| PageUp · PageDown | Increase or decrease by 10 times step |
| Home · End | Jump to min or max (nothing happens when neither is set) |
| Pressing a button | One step; held for over 400 ms it repeats every repeat ms |
| Esc | Stops the repeat and cancels the edit |
The buttons are not tab stops (tabindex="-1"); keyboard users press the arrow keys in the input. The input has role="spinbutton" with aria-valuenow, aria-valuemin and aria-valuemax, and the buttons are named in the grid language ("Increase qty"). At a limit, that button gets disabled and aria-disabled.
An empty value starts from min (or 0) and takes one step. The repeat stops when the pointer is released or leaves the button, or when the input loses focus.
Typed values are not corrected
If you type a number outside the range, the editor does not quietly change it to min or max. Validation refuses it on commit and shows why (Must be 10 or less.), so keyboard users can see the reason. A validation.min or validation.max you set yourself wins.
Gallery example: edit-stepper
See also
- Cell editing: input rules, validation, keys that start an edit
- Built-in renderers