Skip to content

Commit 889378b

Browse files
docs(treelist): improve incell editing notes
1 parent 160505c commit 889378b

File tree

2 files changed

+67
-10
lines changed

2 files changed

+67
-10
lines changed

components/grid/editing/incell.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ When using an [editor template]({%slug components/grid/features/templates%}#edit
270270
}
271271
}
272272

273-
* Using an editor template requires that there is a focusable element in the editor template in order to maintain the tab order when using the keyboard. For exapmle, if you prevent editing based on a runtime condition (setting `Editable=false` for the entire column does not require this), you must provide a focusable element, here is one way to add such an element:
273+
* Using an editor template requires that there is a focusable element in the editor template in order to maintain the tab order when using the keyboard. For example, if you prevent editing based on a runtime condition (setting `Editable=false` for the entire column does not require this), you must provide a focusable element, here is one way to add such an element:
274274

275275
**.razor**
276276

components/treelist/editing/incell.md

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -310,29 +310,88 @@ Editing is cancelled for the first record.
310310

311311
## Notes
312312

313-
* The `OnCreate` event will fire as soon as you click the `Add` button so you can add the new row to the treelist `Data` - this will let it show up in the treelist, and then enter edit mode for the first editable column (to fire `OnEdit` and let the user alter the column). This means you should have [default values]({%slug grid-kb-default-value-for-new-row%}) that satisfy any initial validation and requirements your models may have.
313+
The InCell edit mode provides a specific user experience that aims at fast efficient data entry. This requires that it behaves a differently than other edit modes. Please review the notes below to get a better understanding of these specifics:
314+
315+
316+
* [General](#general)
317+
* [Events Sequence](#events-sequence)
318+
* [Editor Template](#editor-template)
314319

315-
* This means that there is no actual inserted item, an item in InCell editing is always in Edit mode, never in Insert mode. Thus, you cannot use the `InsertedItem` field of the treelist [State]({%slug treelist-state%}). If you want to insert items programmatically in the treelist, alter the `Data` collection, and use the `OriginalEditItem` feature of the state (see the [Initiate Editing or Inserting of an Item]({%slug treelist-state%}#initiate-editing-or-inserting-of-an-item) example - it can put the InLine and PopUp edit modes in Insert mode, but this cannot work for InCell editing).
320+
321+
### General
316322

317323
* When the InCell Edit Mode is enabled and you want to enable item selection a `<TreeListCheckboxColumn />` must be added to the `<Columns>` collection. More information on that can be read in the [Selection]({%slug treelist-selection-overview%}#notes) article.
318324

319325
<!-- * To see how to select the row that is being edited in InCell edit mode without using a `<TreeListCheckboxColumn />` check out the [Row Selection in Edit with InCell EditMode]({%slug grid-kb-row-select-incell-edit%}) Knowledge Base article. -->
320326

321327
* It is up to the data access logic to save the data once it is changed in the data collection. The example above showcases when that happens and adds some code to provide a visual indication of the change. In a real application, the code for handling data updates may be entirely different.
322328

329+
* If validation is not satisfied, you cannot open another cell for editing, and you need to either satisfy the validation, or press `Esc` to revert its value to the original one that should, ideally, satisfy validation.
330+
331+
* Editing (and inserting) items is a separate operation from expanding items. Therefore, if you click the "Add" button on a row that is not expanded, there will be an `OnCreate` call to insert a record as its child, but you will not see it in the UI opened for editing, because the treelist must not arbitrarily expand items - there can be other handlers, business logic or load-on-demand attached to that action, and that changes the users state - and the treelist should not invoke these changes arbitrarily. This also applies to items that currently have no child items - they will have a child item, but it will not expand and open for editing.
332+
333+
### Events Sequence
334+
335+
* The `OnCreate` event will fire as soon as you click the `Add` button so you can add the new row to the treelist `Data` - this will let it show up in the treelist, and then enter edit mode for the first editable column (to fire `OnEdit` and let the user alter the column). This means you should have [default values]({%slug grid-kb-default-value-for-new-row%}) that satisfy any initial validation and requirements your models may have.
336+
337+
* This means that there is no actual inserted item, an item in InCell editing is always in Edit mode, never in Insert mode. Thus, you cannot use the `InsertedItem` field of the treelist [State]({%slug treelist-state%}). If you want to insert items programmatically in the treelist, alter the `Data` collection, and use the `OriginalEditItem` feature of the state (see the [Initiate Editing or Inserting of an Item]({%slug treelist-state%}#initiate-editing-or-inserting-of-an-item) example - it can put the InLine and PopUp edit modes in Insert mode, but this cannot work for InCell editing).
338+
339+
* The `OnEdit` event fires once per row - when the first cell from a row is opened for editing. Moving with the keyboard (`Tab` or `Shift+Tab`) between its cells does not fire events so that the treelist does not re-render, and there is no lag for the user, especially from slow data operations such as `OnUpdate`. This caters to the user experience so they can input data quickly and efficiently.
340+
341+
* If you use the keyboard to navigate between open cells, `OnUpdate` will fire only when the entire row loses focus, not for each cell, so you will not need additional actions to open a new cell.
342+
343+
* If there is a cell that is being edited at the moment, clicking on a cell will first close the current cell and fire `OnUpdate`. To start editing the new cell in such a case you will need a second click.
344+
323345
* The `OnCancel` event can work only with the keyboard (when you press `Esc`). The `Cancel` command button is not supported. Clicking outside the currently edited cell will trigger the `OnUpdate` event and thus, clicking on the `Cancel` command button will not fire the `OnCancel` event because an update has already occured.
324346

325347

326-
* If there is a cell that is being edited at the moment, clicking on a cell will first close the current cell and fire `OnUpdate`. To start editing the new cell in such a case you will need a second click.
348+
### Editor Template
349+
350+
When using an [editor template]({%slug treelist-templates-editor%}), the grid cannot know what the custom editor needs to do, what it contains, and when it needs to close the cell and update the data, because this is up to the editor. This has the following implications:
351+
352+
* The treelist will still capture `Enter` and `Tab` keypresses when the cell is focused, and will close the cell with the corresponding `OnUpdate` call. You can either use that (e.g., a standard input will let the keypress event propagate to the treelist cell), or you can prevent the event propagation and use only your business logic. If you don't do anything, you will get the default treelist behavior for the keyboard navigation even with custom editors.
353+
354+
* The treelist can no longer capture the `onblur` event in a custom editor like it does for built-in editors. It uses it to call `OnUpdate` when the user clicks away from the current row with the mouse. So, when an editor template is open, clicking away will not close it and save the row.
355+
356+
If you want to get this behavior, you can use the treelist [state]({%slug treelist-state%}) to close the cell and you can also invoke the desired operations on the data according to your business logic. For example, a suitable event the Telerik input components provide is `OnBlur`.
357+
358+
**.razor**
327359

328-
* If you use the keyboard to navigate between open cells, `OnUpdate` will fire only when the entire row loses focus, not for each cell, so you will not need additional actions to open a new cell.
360+
<EditorTemplate>
361+
@{
362+
CurrentlyEditedLine = context as SampleData;
363+
<TelerikTextBox OnBlur="@CloseEditorAndSave"
364+
Width="100%" @bind-Value="@CurrentlyEditedLine.LastName">
365+
</TelerikTextBox>
329366

330-
* If validation is not satisfied, you cannot open another cell for editing, and you need to either satisfy the validation, or press `Esc` to revert its value to the original one that should, ideally, satisfy validation.
367+
}
368+
</EditorTemplate>
331369

332370

333-
* When using an [editor template]({%slug treelist-templates-editor%}), the treelist cannot know what the custom editor needs to do, what it contains, and when it needs to close the cell and update the data, because this is up to the editor. Thus, you can use the treelist [state]({%slug treelist-state%}) to close the cell and invoke the desired operations on the data according to your business logic. For example, a suitable event the Telerik input components provide is `OnChange`.
371+
**C#**
334372

335-
Using an editor template requires that there is a focusable element in the editor template in order to maintain the tab order when using the keyboard. For exapmle, if you prevent editing based on a runtime condition (setting `Editable=false` for the entire column does not require this), you must provide a focusable element, here is one way to add such an element:
373+
SampleData CurrentlyEditedLine { get; set; }
374+
TelerikTreeList<SampleData> TreeList { get; set; }
375+
376+
async Task CloseEditorAndSave()
377+
{
378+
var state = TreeList?.GetState();
379+
if (state.EditItem != null)
380+
{
381+
// we can reuse the code from the OnUpdate handler
382+
await UpdateHandler(new TreeListCommandEventArgs()
383+
{
384+
Item = state.EditItem
385+
});
386+
387+
// use the state to remove the edited item (close the editor)
388+
state.EditItem = null;
389+
state.OriginalEditItem = null;
390+
await TreeList.SetState(state);
391+
}
392+
}
393+
394+
* Using an editor template requires that there is a focusable element in the editor template in order to maintain the tab order when using the keyboard. For example, if you prevent editing based on a runtime condition (setting `Editable=false` for the entire column does not require this), you must provide a focusable element, here is one way to add such an element:
336395

337396
**.razor**
338397

@@ -349,9 +408,7 @@ Editing is cancelled for the first record.
349408
}
350409
</EditorTemplate>
351410

352-
The treelist will also not focus and select the contents of custom editors like it does for the built-in ones.
353411

354-
When keyboard navigation is enabled in the treelist (`Navigable=true`), the grid will capture `Enter` and `Tab` keypresses when the cell is focused, and will close the cell with the corresponding update. You can either use that (e.g., a simple input will let the keypress event propagate to the grid cell), or you can prevent the event propagation and use only your business logic.
355412

356413

357414

0 commit comments

Comments
 (0)