Kendo grid - update row if it is already exists in the grid

1 Answer 144 Views
Grid
jas
Top achievements
Rank 1
jas asked on 18 Jan 2022, 11:35 AM

Dears,

I need help in inline edit grid , i want way in that if user create row first time it add row (e.g item name, quantity), if user add same item again in the grid and that item exists in the grid update the quantity of first record and remove the new record.

 

how can i do that?

 

Thanks

1 Answer, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 21 Jan 2022, 09:53 AM

Hi Jas,

A custom logic achieving this can be implemented with the use of the following DataSiyrce event and methods:

Here is the implementation I came up with:

change: function(e) {
                  if (e.action === "add") {
                    addNewrec = true
                  }
                  if (e.action === "sync" && addNewrec) {
                    addNewrec = false;
                    var newItem = e.items[0];

                    var data = e.sender.data()
                    data.forEach(function(el, idx){
                      if (idx !== 0 && idx !== data.length) {
                        if(el.ProductName === newItem.ProductName) {
                          e.sender.remove(newItem);
                          //increment the desired quantity propery
                          el.set("UnitsInStock", el.UnitsInStock+1)
                        }
                      }
                    });
                    e.sender.sync()
                  }
                }

And a runnable Dojo demo you can examine:

Let me know if you have any questions.

Regards,
Nikolay
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Grid
Asked by
jas
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Share this question
or