After insert I use delete but I can get last add row primary key

Dear Sir: I delete my last added row, I can't get ID value.

2024-11-21_194224.png


2024-11-21_194130.png


3 Replies

AR Aishwarya Rameshbabu Syncfusion Team November 22, 2024 10:20 AM UTC

Hi JyongXuan Liu,


Greetings from Syncfusion support.


Based on the information provided, it appears that you are encountering an issue with deleting newly added records in the Syncfusion Grid. After analyzing the code example you shared, we noticed that the visible property of the primary key column in the Syncfusion Grid is set to false. This means the primary key column is not displayed in the UI.


In the Syncfusion Grid, CRUD (Create, Read, Update, Delete) actions are performed based on the primary key column. When a new record is added, if the primary key column is not visible, the primary key for the new record may not be included, resulting in a null ID value when attempting to delete the newly added record.


To address this issue, you can dynamically update the primary key value in the actionBegin event when the primary key column’s visibility is set to false. Below is a code example and a video demonstration for more information:


Index.cshtml

 

<script>

 

    let primaryKeyCounter = 1;

 

    function actionBegin(args) {

 

        if (args.requestType === 'add') {

 

            // Assign a new primary key value programmatically for primary key column

 

            args.data.EmployeeID = primaryKeyCounter;

 

            primaryKeyCounter++; // Increment the counter for the next record

        }

 

    }

 

</script>

 



Sample and vide demonstration: Please find in the attachment.


Additionally, you can handle the dynamic generation of the primary key value on the server side. However, it is essential to ensure that the primary key value is set for newly added records, as the Grid relies on this value to perform CRUD actions.


API References:


actionBegin


If you need any other assistance or have additional questions, please feel free to contact us.


Regards

Aishwarya R


Attachment: 195263SampleAndVideo_58708e7d.zip


JL JyongXuan Liu November 22, 2024 01:38 PM UTC

Dear Sir:

You can see I try to ruturn ID(SQL Server sequence) value to grid row

but fail.

I try use primary key  visible property as true, but the same


2024-11-22_213727.png



AR Aishwarya Rameshbabu Syncfusion Team November 25, 2024 05:47 PM UTC

Hi JyongXuan Liu,


Upon reviewing your query, we have noticed that you are still encountering an issue with deleting the newly added records in the Grid, even when you enable the visibility of the primary key column.


Replicating the Issue:

We have attempted to replicate the issue on our side but were unsuccessful. For your reference, we have attached a sample project and a video demonstration where the primary key column is made visible, allowing records to be added and deleted as expected.

If the issue persists on your end, please provide the following information to help us investigate further:


Additional information:

1.Primary Key: From your screenshot, it seems the 'ID' value is correctly sent to the server during record insertion. Are you still finding null 'ID' values when trying to delete a record?

2.Unique Values: Verify that the primary key column contains unique values, as this is essential for the CRUD operations to function correctly in the Grid.

3.Syncfusion Version: Let us know which version of the Syncfusion package you are currently using.

4.Video Demonstration: Provide a video demonstration of the issue replication process, so we can better understand the problem.

5.Sample Project: Try reproducing the issue using the attached sample project or share a simplified version of your project that demonstrates the problem.


Providing these details will assist us significantly in diagnosing the problem and offering the most effective solution.


Regards

Aishwarya R


Attachment: UpdatedSampleAndVideo_258b7cbf.zip

Loader.
Up arrow icon