Putting custom get/set in DataSource Schema or Kendo Grid

3 posts, 1 answers
  1. Eric
    Eric avatar
    47 posts
    Member since:
    Aug 2012

    Posted 30 Mar 2017 Link to this post


    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. Answer
    Boyan Dimitrov
    Boyan Dimitrov avatar
    2062 posts

    Posted 03 Apr 2017 Link to this post

    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.

    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.
  3. Eric
    Eric avatar
    47 posts
    Member since:
    Aug 2012

    Posted 07 Apr 2017 in reply to Boyan Dimitrov Link to this post

    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.


Back to Top