This is a migrated thread and some comments may be shown as answers.

Putting custom get/set in DataSource Schema or Kendo Grid

2 Answers 145 Views
Grid
This is a migrated thread and some comments may be shown as answers.
IT Dept
Top achievements
Rank 1
IT Dept asked on 30 Mar 2017, 07:38 PM

Hello,

I'm trying to implement a Kendo grid where two cells update each other when changed. I know I could use a calculated column if only one cell was editable and the other was calculated but I'm lost trying to let them both update each other. 

I know I could do this with a custom Javascript class and get/set methods, where the set for one updates the other, and vice versa.

For Example, say I want a grid of product prices like so:

SKU       Price        Discount        Sale Price
001       20.00          10%              18.00
002       10.00          20%               8.00
...

And I want both the Sale Price and the Discount to be editable: Editing the Sale price should update the discount to the calculated % of Price, and updating the Discount will calculate a new sale price. Furthermore, let's assume I don't actually need to save the sale price, I'm really only loading from my .Net server Sku, Price, and Discount and would like get() on Sale Price to calculate the value to display, and set() on Sale Price to calculate the new discount for saving when I submit my page. 

What is the easiest way to achieve this? Currently I'm defining a Schema in my DataSource and filling it with values then displaying my Grid.

2 Answers, 1 is accepted

Sort by
0
Accepted
Boyan Dimitrov
Telerik team
answered on 03 Apr 2017, 08:43 AM

Hello Eric,

A possible solution would be to update the model total field via the set method in the save event of the grid. For convenience, I created a jsFiddle example which illustrates this in action.

Regards,
Boyan Dimitrov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
IT Dept
Top achievements
Rank 1
answered on 07 Apr 2017, 03:17 PM

Thank you.

That's not quite as elegant as I'd hoped (ie, would be nice if salePrice could be defined as a virtual column with a get() that calcualtes the salePrice, and a set() that calculates a new discountPercentage. That way each such column could have it's update code in one place, rather than adding to the if chain in the save method).

But this will definitely do the job.

Eric

Tags
Grid
Asked by
IT Dept
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
IT Dept
Top achievements
Rank 1
Share this question
or