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

[Solved] Can I set the value of a grid cell during an onSave event?

3 Answers 157 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.
Christopher Ronak
Top achievements
Rank 1
Christopher Ronak asked on 14 Feb 2012, 01:40 AM
Hi,

I have a grid which I've declared using inCell editing
        .Editable(editing => editing.Mode(GridEditMode.InCell))
When the user modifies one value in the grid, I'd like to catch that event and use that value to update another item in the grid - and have that show up on the grid. I don't actually want to save any of these values to the server until the user hits submitChanges() - so the save gets interrupted using a preventDefault().

In my sample function below, I calculate a billable value using the Markup entered by the user. But how do I then get that billable value to show up in the grid cell?

function InvoiceCommitmentsGrid_onSave(e) {
        var values = e.values;
        var markup = parseFloat(values.Markup) / 100;
        var cost = parseFloat(values.InvoiceCostAmount);
        var billable = cost + (cost * markup);
        var dataItem = e.dataItem;
        dataItem.InvoiceBillableAmount = billable;
        e.preventDefault();
    }


Thanks for any help!

Chris

3 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 14 Feb 2012, 01:28 PM
Hello,

Generally speaking you do not need to call the e.preventDefault()method because by default there will not be any request executed until the submit changes is not triggered.
You can use the saveCell method (which accepts a td element) exposed by the Grid object to update the content of the cell which you want to update (your target cell does not need to be in edit mode).
Or you can manually update the content of the cell like shown in the attached project (check the ClientSide.cshtml).
I hope this helps.

All the best,
Petur Subev
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Francisco
Top achievements
Rank 1
answered on 20 Jun 2012, 11:22 PM
Please Help!
I am in the same situation! How to update a cell before manually?
0
Swa
Top achievements
Rank 1
answered on 22 Oct 2012, 10:39 AM
Thnx the post was really helpful
Tags
Grid
Asked by
Christopher Ronak
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Francisco
Top achievements
Rank 1
Swa
Top achievements
Rank 1
Share this question
or