Template Editing in ASP.NET Core Tree Grid Component
18 Nov 20183 minutes to read
Cell edit template
The cell edit template is used to add a custom component for a particular column by invoking the following functions:
-
create - It is used to create the element at the time of initialization.
-
write - It is used to create the custom component or assign default value at the time of editing.
-
read - It is used to read the value from the component at the time of save.
-
destroy - It is used to destroy the component.
Dialog template
The dialog template editing provides an option to customize the default behavior of dialog editing. Using the dialog template, you can render your own editors by defining the mode as Dialog and template as SCRIPT element ID or HTML string which holds the template.
In some cases, you need to add the new field editors in the dialog which are not present in the column model. In that situation, the dialog template will help you to customize the default edit dialog.
In the following sample, treegrid enabled with dialog template editing.
NOTE
The template form editors should have name attribute.
Get value from editor
You can read, format, and update the current editor value in the actionBegin event at the time of setting requestType to save.
In the following code example, the progress value has been formatted and updated.
function actionBegin(args) {
if (args.requestType === 'save') {
// cast string to integer value.
args.data['progress'] = parseFloat(args.form.querySelector("#progress").value);
}
}Set focus to editor
By default, the first input element in the dialog will be focused while opening the dialog.
If the first input element is in disabled or hidden state, focus the valid input element in the actionComplete event based on requestType as beginEdit.
function actionComplete(args) {
// Set initail Focus
if (args.requestType === 'beginEdit') {
(args.form.elements.namedItem('taskName')as HTMLInputElement).focus();
}
}Adding validation rules for custom editors
If you have used additional fields that are not present in the column model, then add the validation rules to the actionComplete event.
function actionComplete(args: DialogEditEventArgs) {
if ((args.requestType === 'beginEdit' || args.requestType === 'add')) {
// Add Validation Rules
args.form.ej2_instances[0].addRules('progress', {max: 100});
}
}NOTE
You can refer to our
ASP.NET Core Tree Gridfeature tour page for its groundbreaking feature representations. You can also explore our ASP.NET Core Tree Grid exampleASP.NET Core Tree Grid exampleto knows how to present and manipulate data.