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

Set other row cells values based on selected DropDownListItem in one cell

5 Answers 1016 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bernard
Top achievements
Rank 1
Bernard asked on 29 Aug 2013, 07:50 AM
Hi,

I'm trying to make a backoffice order editor using catalog with referenced products.

Basically i've a Grid with severals columns
- Product Picture
- Product Code
- Description
- Quantity
- Unit Amount
- VAT Rate
- Total Amount

Product Code editor is a DropDownList on which we can select the desired product.
After selecting product i need to set all others cells values on this row but i've no idea how to do that.

VAT Rate is a ForeingKey Column (DropDownList Editor)

Any help on this ?

Thanks in advance,
Best Regards.

5 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 02 Sep 2013, 07:48 AM
Hi Bernard,

To achieve this you should hook up to the change event of the DropDownList editor and use dataItem (grid), closest (jQuery) and set (model) methods. For example:
change: function() {
    var grid = $("#grid").data("kendoGrid"),
        model = grid.dataItem(this.element.closest("tr"));
 
    model.set("ProductName", "changed");
}

For your convenience I prepared a runnable sample which demonstrates the approach in action:

Regards,
Alexander Valchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Bernard
Top achievements
Rank 1
answered on 04 Sep 2013, 03:59 PM
Hi Alexander,

Thank you very well for you sample, it helps me a lot.

However, it seems to update only the first column of the first row, whatever i change the selected value of the dropdown in another row.

Maybe a problem with :

model = grid.dataItem(this.element.closest("tr"));

Thanks.
0
Alexander Valchev
Telerik team
answered on 05 Sep 2013, 12:11 PM
Hi Bernard,

The problem occurs due to timing issues. At the time when change event handler is executed, the editable cell is already closed and associated HTML elements are not part of the DOM tree anymore.

I can suggest you another similar approach which I believe will fit in your needs. Instead of to the change event you may hook up to the select event. Also instead of set method, you should use the standard "=" operator to change the values.
select: function() {
    var grid = $("#grid").data("kendoGrid"),
        model = grid.dataItem(this.element.closest("tr"));
 
    model.ProductName = "changed";
    model.UnitPrice = 100;
}

For your convenience I updated previous sample:

Regards,
Alexander Valchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
David
Top achievements
Rank 2
answered on 10 Aug 2016, 02:51 PM

Hello,

This solution has helped me greatly. Although I am running into a slight issue with this. After setting the changes to the model dataItem, the Kendo UI Grid does not display the changed values as per the sample.

The changed values will only display once I manually re-filter/re-sort a column. Do you have any ideas what might be causing this?

I am using Kendo UI for ASP.NET MVC for the dropdownlist, but using the same Jquery as the above.

Thank you.

0
Boyan Dimitrov
Telerik team
answered on 12 Aug 2016, 12:50 PM

Hello David,

Updating a data item (model in the code snippet) using dot "." instead of set method will not refresh the Kendo UI Grid. The method refresh of the Kendo UI Grid should be called in order to render all table rows using the current data items.

Regards,
Boyan Dimitrov
Telerik by Progress
 
Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
 
Tags
Grid
Asked by
Bernard
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Bernard
Top achievements
Rank 1
David
Top achievements
Rank 2
Boyan Dimitrov
Telerik team
Share this question
or