In a inline edited grid, when I click on Add toolbar button, I would like to prevent the user from manually entering a value within primary key column as it will be generated automatically. As suggested in documentation below, I set the column to column.allowEditing = false but when clicking Add, the new record row still have the column editable:
Hi Issam DANO,
Greetings from Syncfusion support.
Based on your requirement, you aim to prevent manual editing of the primary key column in Syncfusion Grid while ensuring it automatically generates unique values during record addition. In Syncfusion Grid, primary key columns are inherently protected against editing as they are essential for performing CRUD (Create, Read, Update, Delete) operations. However, when adding a new record, it's still necessary to provide a unique value for the primary key.
To address your need, we leveraged the actionBegin event. Here's how the solution works:
|
App.component.html
<ejs-grid #grid id='Normalgrid' [dataSource]='data' allowPaging='true' [allowSorting]='true' [allowFiltering]='true' [filterSettings]='filterSettings' [pageSettings]='pageSettings' [editSettings]='editSettings' [toolbar]='toolbar' (actionBegin)='actionBegin($event)'> <e-columns> <e-column field='OrderID' headerText='Order ID' width='140' textAlign='Right' isPrimaryKey='true' isIdentity='true'></e-column> ……….. </e-columns>
</ejs-grid>
|
|
App.component.ts
actionBegin(args) { if (args.requestType === 'add') { // Assign a new primary key value programmatically args.data.orderID = this.primaryKeyCounter; this.primaryKeyCounter++; // Increment the counter for the next record } }
|
Sample: Gcyyxg (forked) - StackBlitz
Screenshot:
API References:
If you need any other assistance or have additional questions, please feel free to contact us.
Regards
Aishwarya R
Hi Aishwarya,
Thank you very much for this.
BR
Hi Issam DANO,
We are happy to hear that the provided solution was helpful. Please get back to us if you need any other assistance.
Regards
Aishwarya R