create third column in kendo grid with de sum of column one and two.

1 Answer 72 Views
Grid
Yonatan
Top achievements
Rank 1
Yonatan asked on 06 Aug 2021, 10:07 AM

I want the sum of two columns to be added to another column in the kendo grid. Now it is showing that NaN when I use ClientTemplate whereas in the case of ClientGroupColumnTemplate shows the correct result. In my case, I want the result in another column instead of a group column any help?

.Columns(c =>

    {  c.Bound(p => p.field1).Title("F1");
       c.Bound(p => p.field2).Title("F2");
       c.Bound(p => p.Total).Title("Total").ClientTemplate("#=calculate(data)#");
})

<script>
    function calculate(data) {
        field1 + p.field2;
        return result;

</script>

1 Answer, 1 is accepted

Sort by
1
Accepted
Anton Mironov
Telerik team
answered on 11 Aug 2021, 06:45 AM

Hello Yonatan,

Thank you for the code snippet and details provided.

In order to achieve the desired behavior, I would recommend trying the following implementation for the "Total" column:

columns.Template(c => { }).ClientTemplate("#=calculateField(data)#").Title("Total");
And the JavaScript function:
    function calculateField(data) {
        return data.Field1 + data.Field2;
    }
Attached is a sample project that I prepared for the case. It includes the approach above.

Make the needed tests locally with the project attached and let me know if further assistance is needed.

 

Kind Regards,
Anton Mironov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Yonatan
Top achievements
Rank 1
commented on 04 Oct 2021, 03:14 PM

Thank you, Anton Mironov, It works perfectly. 
Anton Mironov
Telerik team
commented on 07 Oct 2021, 07:09 AM

Hi Yonatan,

I am glad to hear that the required behavior is now achieved.

If further assistance for anything else Kendo-related is needed, do not hesitate to contact me and the team.

Best Regards,
Anton Mironov
Tags
Grid
Asked by
Yonatan
Top achievements
Rank 1
Answers by
Anton Mironov
Telerik team
Share this question
or