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

Dynamically fill column in kendo grid

3 Answers 362 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Neha
Top achievements
Rank 1
Veteran
Neha asked on 27 Aug 2020, 07:48 AM

Hi

I am using kendo grid inline editing . I want to dynamically fill the value of one column based on the values added from 2 other  columns.
example:

Col A+ Col B = Col C

Fill the value dynamically whiling editing or new insert within in cell kendo grid  

3 Answers, 1 is accepted

Sort by
0
Patrick | Technical Support Engineer, Senior
Telerik team
answered on 28 Aug 2020, 07:04 PM

Hi Neha,

By utilizing the Column.Template(), the fields from other columns can be mathematically displayed:  

Columns

    .Columns(columns => {
        columns.Bound(p => p.ProductName);
        columns.Bound(p => p.UnitPrice).Width(140);
        columns.Bound(p => p.UnitsInStock).Width(140);
        columns.Template("#=calcColumns(data)#").Title("UnitPrice * UnitsInStock");
        columns.Command(command => { command.Edit(); command.Destroy(); }).Width(300);
    })

JavaScript

    function calcColumns(e) {
        //Multipies UnitPrice to UnitsInStock
        return e.UnitPrice * e.UnitsInStock;
    }

Please take a look at the attached gif(Unzip ConditionalColumn.zip) which demonstrates the above.  Hope this information helps!  

Regards,
Patrick
Progress Telerik

Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive , special prizes and more, for FREE?! Register now for DevReach 2.0(20).

0
Neha
Top achievements
Rank 1
Veteran
answered on 31 Aug 2020, 09:27 AM
It is working fine but not as expected. I want the col C to be filled at the time when user enter values in Col A or Col B or both.
Currently its working once I save the values but not at the time of entering the values. I want the col C to be updated at the time of entry only.
0
Patrick | Technical Support Engineer, Senior
Telerik team
answered on 01 Sep 2020, 05:17 PM

Hello Neha,

The reason it is saving upon entering the values is because the template is using the dataItems values rather than the DOM elements.  One way to overcome this is to use AutoSync(true) in the Kendo UI Grid's datasource.  This will update the record upon blurring from the editor, and configure the template.  

    .DataSource(dataSource => dataSource
        .Ajax()
        .AutoSync(true)
        //....
    )

Regards,
Patrick
Progress Telerik

Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive , special prizes and more, for FREE?! Register now for DevReach 2.0(20).

Tags
Grid
Asked by
Neha
Top achievements
Rank 1
Veteran
Answers by
Patrick | Technical Support Engineer, Senior
Telerik team
Neha
Top achievements
Rank 1
Veteran
Share this question
or