How to detect if data in input type number kendo grid is from the kendo grid read method or from the user ?

0 Answers 154 Views
Grid MVVM
youssef
Top achievements
Rank 1
youssef asked on 28 Jun 2023, 09:04 AM | edited on 28 Jun 2023, 09:04 AM

I have this field in my kendo grid column :

field: "tauxAcquisEntree",
template: '#if (tauxAcquisEntree === 0){#'
                    + '<div class="text-right">#= tauxAcquisEntree #</div>'
                    + '# }else if (tauxAcquisEntree > 1 ){#'
                    + '<div class="d-flex justify-content-end"><div class="input-group d-flex flex-nowrap percent-input"> <input id="fraisent" name="fraisent" value="#= tauxAcquisEntree #" max="4"   class="form-control text-center"  min="1" type="number" step=1 pattern="[0-9]$" autocomplete="off"   /> </div></div>'
                    + '# }else{#'
                    + '<div id="fraisOne" name="fraisOne" class="d-flex justify-content-end"><div class="input-group d-flex flex-nowrap percent-input"> <input value="#= tauxAcquisEntree #" class="form-control text-center" max="1" min="1"  type ="number" pattern="[0-1]$" autocomplete="off" readonly  /> </div></div>'
                    + '# }#'
                ,

I have a condition when i get the field "tauxAcquisEntree" from the "database"  if it's equal to "1" the input type number becomes readonly.

The problem is when the user changes the value of the input type number in the front and it's equal to "1" the template condition gets triggered which is a behavior that i don't want to happen.

To summarize how can i get the if condition in the template to be applied only if the value if from backend or the database (and not what the user typed) ?

Georgi Denchev
Telerik team
commented on 03 Jul 2023, 07:40 AM

Hello, Youssef,

Thank you for the provided details.

In order for this to work on a per row basis, you'll have to add an additional field to the dataItem(row data). It can be called "userEdited" and its default value(that comes from the server) will be false.

Then, when the user edits the value of the cell, you can update the dataItem and set the value to `true`.

After that you just need to include the additional check in the template:

else if (tauxAcquisEntree > 1 && !userEdited)

The template is always re-rendered on any change and there is no way to prevent this behavior. That is why an additional check is required.

Best Regards,

Georgi

No answers yet. Maybe you can help?

Tags
Grid MVVM
Asked by
youssef
Top achievements
Rank 1
Share this question
or