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

Create calculated value for Grid

3 Answers 697 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 01 Mar 2012, 03:04 AM
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

3 Answers, 1 is accepted

Sort by
0
Mat
Top achievements
Rank 1
answered on 05 Apr 2012, 03:30 PM
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
0
Hammad
Top achievements
Rank 1
answered on 13 Apr 2012, 12:48 PM
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
0
quaso
Top achievements
Rank 1
answered on 11 Apr 2013, 02:18 PM
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
}
Tags
Data Source
Asked by
Jeff
Top achievements
Rank 1
Answers by
Mat
Top achievements
Rank 1
Hammad
Top achievements
Rank 1
quaso
Top achievements
Rank 1
Share this question
or