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

Updating the value of a non-editable cell

6 Answers 1625 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 2
Iron
John asked on 21 Feb 2019, 10:40 PM

Hi,

I hoping this will be a easy answer.

I have a grid and to keep it simple it only has two columns. Quantity and Value. There is an additional JavaScript variable called 'price'. In this example price = 10.

Quantity is inline editable, and Value is defined in the schema as being { editable: false }

When the user clicks the Quantity cell and enters a new number, I need the cell next to it (Value) to recalculate and display the new number in Quantity * price.

So, initially the grid row would be Quantity 0, Value 0.

User enters 10 in Quantity. Value changes to 100.

For some reason I just can't get this to work. Any help would be appreciated!

6 Answers, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 25 Feb 2019, 01:12 PM
Hi John,

A possible solution would be to enable the editing of the Value field on dataSource level, but configure the column as non editable.

e.g.

{ field: "value",editable: function(){
  return false
}

Below you will find a small sample which demonstrates the above approach. Please examine it and let me know if it helps:



Regards,
Georgi
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.
0
John
Top achievements
Rank 2
Iron
answered on 25 Feb 2019, 08:48 PM

Hi Georgi,

Thanks for the reply. That looks like the solution I needed, but unfortunately it didn't quite work.

First thing is that I'm restricted to using an older version on Kendo (v2016.1.112), and the 'editable' column configuration to return false doesn't seem to work for me. Switching to the latest version of Kendo, and that worked. There are plans to upgrade to the latest Kendo, but...that's a whole other story.

But, even on the latest Kendo version I found that the script to update the value column always seemed to use the previous number entered in the quantity cell. No idea why, it works perfectly well in your code snippet.

Also, in your example the spin control for the quantity cell didn't trigger the function, so that doesn't update the 'value' cell.

However, I did find a work around. I used: grid.bind("save", grid_save); And in that function I calculated the new 'value' when the quantity is updated and then set the new value into the destination cell. I found an example of a kendoFastReDrawRow function. I modified that to update on single cell on a row in the grid.

It works OK. Both solutions just feel like too much hard work for something that seemed simple on the face of it.

Cheers,
John

 

 

0
Georgi
Telerik team
answered on 27 Feb 2019, 11:37 AM
Hi John,

The issue related with the old value depends might be related to the event you are using - if you are using some of the numeric text box events, the value might not yet be updated when the event is triggered. To avoid this I would recommend you to access the value directly from the input element.

Furthermore, regarding the old version. You could achieve the same by using a template column and update the html of the cell manually. Below you will find a sample which demonstrates the same approach:


Finally, the value does not update since the input event is used which does not fire when the value is change through the spinners. To avoid that you could use the blur event.


Regards,
Georgi
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.
Lee
Top achievements
Rank 2
Bronze
Bronze
Bronze
commented on 11 Jan 2024, 06:14 PM

The linked Dojo doesn't work. 
Martin
Telerik team
commented on 15 Jan 2024, 09:34 AM

Hello, Lee,

In the example, if you edit the price and the quantity cells, the third column cell will be updated respectively as per the code in the save event ( price * quantity). Could you please let me know what does not work as expected?

0
John
Top achievements
Rank 2
Iron
answered on 28 Feb 2019, 07:04 PM

Hi Georgi,

Thanks for the reply. What I have is working now, but I will circle back around and try your suggestion when I can. I'll update this thread when I try it.

Cheers
John

0
Georgi
Telerik team
answered on 04 Mar 2019, 09:08 AM
Hello John,

Take your time to test the approach from my previous reply and let me know how it works for you.


Regards,
Georgi
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.
0
NHJ
Top achievements
Rank 1
answered on 27 Feb 2020, 02:49 AM
The best answer. I've been searching for this answer for a long time.
Tags
Grid
Asked by
John
Top achievements
Rank 2
Iron
Answers by
Georgi
Telerik team
John
Top achievements
Rank 2
Iron
NHJ
Top achievements
Rank 1
Share this question
or