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

Calculated Columns

3 Answers 502 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Pierre
Top achievements
Rank 1
Pierre asked on 08 Jun 2012, 10:24 AM
Hi,

I have a grid with columns Qty, Price and Total.  When the user changes the Qty and clicks on Update, I want to recalculate the total and update the Total cell.  How would you do that?  The grid is setup with GridEditMode.InLine.

And while were adding things up, how do you do a grand total and display it in the footer?

Thx,

PT

3 Answers, 1 is accepted

Sort by
0
Jon
Top achievements
Rank 1
answered on 08 Jun 2012, 11:27 PM
I am trying to do something similar, any idea how to do this?
0
Pierre
Top achievements
Rank 1
answered on 18 Jun 2012, 02:04 PM
400+ views and no answer. Either it's really hard to do or a really dumb question!  KendoUI staff reading these things?
0
Pierre
Top achievements
Rank 1
answered on 19 Jun 2012, 07:13 AM
I think I figured this out after numerous try-on-error.

To make this work I had to add an aggregates in the DataSource and set ServerOperation to false.

Don't know why but that seems to work.  Maybe someone can shed some light on this?

@(Html.Kendo().Grid(Model.Products)
    .Name("FabricGrid")
    .Columns(columns =>
    {
        columns.Bound(p => p.Fabric).ClientFooterTemplate("Fabric Count: #=count#");
        columns.Bound(p => p.Pattern);
        columns.Bound(p => p.Description);
        columns.Bound(p => p.UPrice).Format("{0:C}");
        columns.Bound(p => p.Qty).Width(150).ClientFooterTemplate("Total :").Format("{0:0.00}");
        columns.Bound(p => p.Total).ClientFooterTemplate("#=sum#");
        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)
        .Aggregates(aggregates =>
        {
            aggregates.Add(p => p.Fabric).Count();
            aggregates.Add(p => p.Total).Sum();
        })
        .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"))
    )
)
Tags
Grid
Asked by
Pierre
Top achievements
Rank 1
Answers by
Jon
Top achievements
Rank 1
Pierre
Top achievements
Rank 1
Share this question
or