BoldDeskWe are launching BoldDesk on Product Hunt soon. Learn more & follow us.
Hello, I am trying to implement the solution that would support properly use of templates, context based custom edit rules, and validations for that. First, let us start with example data type. Let it be the following data types:
type TDimensions = {
width: number;
height: number;
}
type TItem = {
id: string;
name: string;
dimensions: TDimensions
}
There is nothing complex here, except the dimensions utilizes the use of custom non-promitive data type. Then, I create the grid for my data type:
Regarding name requirement rule, it is trivial. However, with dimensions requirement it is complex, and makes me wonder if Syncfusion Angular is even able to support such use cases. The problem here is that I am unable to provide any reasonable rule that would allow me to achieve the following:
When I try to set that dimensions should be required, then on save I get the following error: "Error: this.inputElement is null". As far as I understand, Syncfusion is unable to deduce any field that would be "dimensions". But I can not provide any such field, since "dimensions" is not a primitive type, thus it is the reason why I use edit template for two values. And I need these two values to be in a single column, since they are not separate contextually (as validation requirements mentioned show this).
So, to sum it all up, my questions would be the following:
Finally, you may use the following code which includes also the sample I have described in this post: https://stackblitz.com/edit/angular-dtah5k-zftrim . Feel free to use it and modify. Thank you for your help in advance.
Hi Customer,
Greetings from Syncfusion.
From your shared details we suspect that you need to apply custom validation rules for Width and Height (Dimensions) while on Editing. To achieve this, we have perform Validation using CustomValidation rules feature available in TreeGrid. With this we can define our own custom rules.
Refer to the documentation link:- https://ej2.syncfusion.com/angular/documentation/treegrid/editing/validation#custom-validation
Refer to the code below:-
App.Component.html:-
<ejs-treegrid #itemsGrid id="itemsGrid" [treeColumnIndex]="1" [dataSource]="items" [toolbar]="itemsToolbar" [editSettings]="itemsEditSettings" [allowPaging]="true" [pageSettings]="{ pageSize: 10 }" [allowSorting]="true" [allowTextWrap]="true" [textWrapSettings]="{ wrapMode: 'Header' }" [allowSelection]="true" (actionBegin)="actionBegin($event)" > <e-columns> </e-column> <e-column field="width" width="100" headerTextAlign="center" textAlign="center" headerText="Height" [validationRules]="customrulewidth" > </e-column> <e-column field="height" width="100" headerTextAlign="center" textAlign="center" headerText="Height" [validationRules]="customrule" > </e-column> </e-columns>
App.Component.ts:-
public customFnWidth(args) { if (args.value > 0 && args.value < 1000) { return true; } }
public ngOnInit() : void {
this.itemsToolbar = ['Add', 'Edit', 'Delete', 'Update', 'Cancel']; this.customrulewidth = {required: true, minLength: [ this.customFnWidth, 'value width must be within range [0,1000]', ], }; this.customrule = { required: true, minLength: [this.customFn, 'value height must be within range [0,1000]'], };
}
|
Modified Sample link:- https://stackblitz.com/edit/angular-dtah5k-934f3n?file=app.component.html
Screenshot:-
Note:- For display purpose, you can use both height and width under same column using template.
For more reference:- https://ej2.syncfusion.com/angular/documentation/grid/editing/validation#custom-validation-based-on-dropdown-change
https://ej2.syncfusion.com/documentation/form-validator/validation-rules/
If we misunderstood your query or your requirement is different from above, share more details to proceed further.
Regards,
Farveen sulthana T