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

Calculated Cells

5 Answers 479 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Pierre
Top achievements
Rank 1
Pierre asked on 18 Jun 2012, 03:59 PM
Hi,

I have a simple grid with Quantity, Unit Price and Total columns and a few others.  The grid is set as GridEditMode.InLine.  When I click on the Edit button of a row I can change the Quantity value.  Once changed, when I click on the Update button I'd like the Total column to reflect the changes: Total = Qty * UPrice.

Here's the grid:
@(Html.Kendo().Grid(Model.Products)
    .Name("FabricGrid")
    .Columns(columns =>
    {
        columns.Bound(p => p.Fabric);
        columns.Bound(p => p.Pattern);
        columns.Bound(p => p.Description);
        columns.Bound(p => p.UPrice);
        columns.Bound(p => p.Qty).Width(150);
        columns.Bound(p => p.Total);
        columns.Command(command => command.Edit()).Width(110);
        columns.Command(command => command.Destroy()).Width(110);
    })
    .Scrollable()
    .Sortable()   
    .Editable(editable => editable.Mode(GridEditMode.InLine))
    .DataSource(dataSource => dataSource
        .Ajax()
        .ServerOperation(false)
        .Model(model => model.Id(p => p.ProductId))
        .Events(events => events.Error("error_handler"))
        .Update(update => update.Action("Product_Update", "ShoppingCart"))
        .Destroy(destroy => destroy.Action("Product_Delete", "ShoppingCart"))
    )
)

I tried to update the ModelState but the display doesn't change.

Thanks for your help.

5 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 19 Jun 2012, 06:23 AM
Hi,

 This should happen automatically if you set the client template for your column:

columns.Bound(p => p.Total).ClientTemplate("#= Qty * UPrice #");

Regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Pierre
Top achievements
Rank 1
answered on 19 Jun 2012, 07:08 AM
Worked
0
Accepted
Atanas Korchev
Telerik team
answered on 19 Jun 2012, 07:14 AM
Hello Pierre,

 You can use the kendo.format function to specify the format in the template:

.ClientTemplate("#= kendo.format('{0:c}', Qty * UPrice) #");

You can find more info here: http://www.kendoui.com/documentation/framework/globalization/overview.aspx 

Regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Pierre
Top achievements
Rank 1
answered on 19 Jun 2012, 07:54 AM
Thanks, that worked.
0
Pushkar
Top achievements
Rank 1
answered on 20 May 2013, 07:46 AM
It works, but the 'Total' doesent change on the client when i change 'Qty' or 'UPrice'? Can you show an example for Asp.Net mvc?
Tags
Grid
Asked by
Pierre
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Pierre
Top achievements
Rank 1
Pushkar
Top achievements
Rank 1
Share this question
or