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

Update cell based on changes on another cell

2 Answers 48 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jimmy
Top achievements
Rank 1
Iron
Veteran
Jimmy asked on 01 Jun 2019, 09:38 AM

Hi

I have Grid with 4 columns. When I edit a row, enter number in cell 2, I want to update cell 4 with the result of cell 2 - cell 3.

Can anyone advice how I can do this urgently? Thanks in Advance

Below is the code of my grid

 

@(Html.Kendo().Grid<TransactionCoBroker>()
.Name("GridCommExCoBroker")
.Editable(editable => editable.Mode(GridEditMode.InLine))
.Columns(columns =>
{
    columns.Command(c => c.Edit());
    columns.Bound(u => u.Name).Title("Name");
    columns.Bound(u => u.FNet).Title("Net"));
    columns.Bound(u => u.FTax).Title("Tax"));
    columns.Bound(u => u.FGross).Title("Amount"));
})
.DataSource(dataSource => dataSource
.Ajax()
.Model(model =>
{
    model.Id(id => id.ICobrokerId);
    model.Field(p => p.UName).Editable(false);
    model.Field(p => p.FNet).Editable(true);
    model.Field(p => p.FTax).Editable(true);
    model.Field(p => p.FGross).Editable(false);
})
.Events(e => e.Error("onError").RequestEnd("onRequestEnd"))
.ServerOperation(true)
.Read(r => r.Url("?handler=GetExCoBrokerComm").Data("GetTransID"))
.Update(r => r.Url("?handler=SaveBrokerComm").Data("GetTransID"))))

2 Answers, 1 is accepted

Sort by
0
Jimmy
Top achievements
Rank 1
Iron
Veteran
answered on 04 Jun 2019, 07:21 AM

Got the answer from support.

 

// add edit event handler

    .Events(x=> x.Edit("onEdit"))

// edit event handler

    function onEdit(e) {
        e.container.find('[name="FNet"]').on('change', function () {
            e.model.set('FGross', +$(this).val() - e.model.FTax)
        })
    }

 

Thanks!

0
Tsvetomir
Telerik team
answered on 05 Jun 2019, 12:55 PM
Hi Jimmy,

Thank you for sharing the solution with the community.

In general, when a field in the model has to be programmatically updated, the recommended way to go is to make use of the set() method. It accepts as arguments the field of the model and the new value. More information could be found here:

https://docs.telerik.com/kendo-ui/api/javascript/data/observableobject/methods/set


Best regards,
Tsvetomir
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Jimmy
Top achievements
Rank 1
Iron
Veteran
Answers by
Jimmy
Top achievements
Rank 1
Iron
Veteran
Tsvetomir
Telerik team
Share this question
or