Calculated Cells

Thread is closed for posting
6 posts, 1 answers
  1. Pierre
    Pierre avatar
    28 posts
    Member since:
    Jun 2012

    Posted 18 Jun 2012 Link to this post

    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.
  2. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 19 Jun 2012 Link to this post

    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!
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Pierre
    Pierre avatar
    28 posts
    Member since:
    Jun 2012

    Posted 19 Jun 2012 Link to this post

    Worked
  5. Answer
    Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 19 Jun 2012 Link to this post

    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!
  6. Pierre
    Pierre avatar
    28 posts
    Member since:
    Jun 2012

    Posted 19 Jun 2012 Link to this post

    Thanks, that worked.
  7. Pushkar
    Pushkar avatar
    2 posts
    Member since:
    May 2013

    Posted 20 May 2013 Link to this post

    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?
Back to Top
UI for ASP.NET MVC is VS 2017 Ready