Programmatically set value to treelist cell

1 Answer 163 Views
TreeList
Josetuttu
Top achievements
Rank 1
Josetuttu asked on 18 Aug 2022, 01:33 PM

How can I set value programmatically to a cell in Treelist from javascript after the data is loaded?

Say I have quantity and price, I need to update the total amount column when I change value quantity or price.

1 Answer, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 23 Aug 2022, 08:26 AM

Hello Josetuttu,

In the given scenario it is best to display the total amount column with a template where its value is the quality multiplied by the price. This way once the price or the quantity is updated the total amount will automatically update as well.

template: "#= data.Price*data.Quantity #"

Another option to update a model property is using the set() method.

Let me know if this is what you are looking for.

Regards,
Nikolay
Progress Telerik

The Premier Dev Conference is back! 

Coming to you live from Progress360 in-person or on your own time, DevReach for all. Register Today.


Josetuttu
Top achievements
Rank 1
commented on 29 Aug 2022, 01:42 PM

Thanks Nikolay. I was trying the set method itself. But the set method is expecting 3 parameters and I couldn't find any documentation or example regarding that. 
The problem I faced was that the column I was trying to set was marked as editable false in the schema since it is a calculated field. This was preventing setting the value to the field. I assume this is not a desirable behavior as making it editable will allow user to change value of a calculated field. Nonetheless, I made it editable in the schema and close the cell when user tries to edit it.
Nikolay
Telerik team
commented on 01 Sep 2022, 08:08 AM

Hi Josetuttu,

Thank you for following up.

Closing the cell the user tries to edit is a valid solution. You can also use the columns.editable configuration and set the function no return false.

The set() method actually expects two parameters: the model property and the new value for it. Am I missing something?

Regards,

Nikolay

Josetuttu
Top achievements
Rank 1
commented on 02 Sep 2022, 01:16 PM

Dear Nikolay,

Please find below the screenshot of set function expecting 3 parameters. This is taken from inspection window and treelist demo.

 

Regards

Jose Tuttu George

Nikolay
Telerik team
commented on 07 Sep 2022, 08:39 AM

Hi Josetuttu,

Here is the internal implementation of the set() method expecting only two parameters - field and value:

 set: function(field, value) {
            var that = this,
                isSetPrevented = false,
                composite = field.indexOf(".") >= 0,
                current = kendo.getter(field, true)(that);

            if (current !== value) {
                if (current instanceof Observable && this._handlers[field]) {
                    if (this._handlers[field].get) {
                       current.unbind(GET, this._handlers[field].get);
                    }
                    current.unbind(CHANGE, this._handlers[field].change);
                }

                isSetPrevented = that.trigger("set", { field: field, value: value });

                if (!isSetPrevented) {
                    if (!composite) {
                        value = that.wrap(value, field, function() { return that; });
                    }
                    if (!that._set(field, value) || field.indexOf("(") >= 0 || field.indexOf("[") >= 0) {
                        that.trigger(CHANGE, { field: field });
                    }
                }
            }

            return isSetPrevented;
        },

Regards,

Nikolay

 

Tags
TreeList
Asked by
Josetuttu
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Share this question
or