Create calculated value for Grid

4 posts, 0 answers
  1. Jeff
    Jeff avatar
    3 posts
    Member since:
    Feb 2012

    Posted 29 Feb 2012 Link to this post

    I have a data source returning Units and Price.  I need to create a column, Extende Price, in a grid to display:

    Units    | Price | Extended Price (Units * Price)

    I can't see how I can do this.

    Jeff

  2. Mat
    Mat avatar
    13 posts
    Member since:
    Mar 2012

    Posted 05 Apr 2012 Link to this post

    You need to create a 'fake' column. Something along the lines of:
    columns: [
                    { field: "units", title: "Units" },
                    { field: "price", title: "Price" },
                    { field: null, title: "Extended Price", template: '#= units * price #' }
                ]


    Regards,
    Mat

  3. Hammad
    Hammad avatar
    4 posts
    Member since:
    Jul 2008

    Posted 13 Apr 2012 Link to this post

    How can i set the value of a field in a model?

    I have almost same scenario like @poster

    ProductID | Quantity | UnitPrice | TotalPrice

    in the save event of Grid, i am using jQuery ajax call to update quantity to the server. After that i need to update the Total Price

    I am trying:

    $("#cart_results").kendoGrid(
    {
       
    //some config of grid,
        //save event handler
        save: function (e)
        {
             //after my ajax call
             e.model.set("TotalPrice",e.model.UnitPrice * e.values.Quantity);
        }
        //some other config of grid
    }


    but it still shows old value of TotalPrice

    Console of Safari shows no errors

    I dont want a calculated column

  4. quaso
    quaso avatar
    1 posts
    Member since:
    Jun 2006

    Posted 11 Apr 2013 Link to this post

    Try to update the datasource instead of the model:


    $("#cart_results").kendoGrid(
    {
        //some config of grid,
        //save event handler
        save: function (e) 
        {
             //after my ajax call
            this.dataSource.getByUid(e.model.uid).set("TotalPrice",e.model.UnitPrice * e.values.Quantity); 
        }
        //some other config of grid
    }

Back to Top