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

Best way to set Default Values dynamically?

1 Answer 519 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Klas
Top achievements
Rank 1
Klas asked on 09 Jan 2013, 04:09 PM
I am struggling a bit with this. I need to be able to set the Default values dynamically based on previously entered values. Currently I am storing the values in Session variables and pulling them with a regular jsonget. My problem is that I can't get the foreignkey dropdownlists to actually set the values, it sets them visually but when I try to update the popup. Note that I use the MVC extension.

Obviously if there are better way to handle dynamic default values I'd be happy to know.

I tried setting this value manually to a specific value also but it gave the same results. I have AutoBind false btw.

This is how I do it now (on the Edit event).

   if (insertMode == true) {
            $.getJSON('/TargetValue/GetDefaultValues', function (data) {
                var kfval = data.kf;
                $("#KeyFigureId").data("kendoDropDownList").value(kfval); <-- The value is set visually but the value registers as 0 when rying to post the save.

            });
            
        }

1 Answer, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 11 Jan 2013, 09:49 AM
Hi Klas,

I believe that the problem comes from the fact that setting the value of the widget via JavaScript does not trigger its change event which is used by the grid to update the bound field. As a workaround I suggest to trigger the change manually after value is set.
var dropDownEditor = $("#KeyFigureId").data("kendoDropDownList");
dropDownEditor.value(kfval);
dropDownEditor.trigger("change"); //force the grid to update the field

I hope this will help.

Kind regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Klas
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Share this question
or