2

ive been using this to set a default text form input on a kendo grid which works fine.

 e.container.find("input[name=policy]").val(lender_policy).change();

however if i try and set a default value of a dropDownListlike below, it sets the value of the dropdownlist, but it insert blank data to the grid and DB. im guessing its because change() may need to be called like the text input but am not sure how that can be done.

 e.container.find("input[name=lender]").data("kendoDropDownList").value(lender);

any help on this would be great.

user2012783
  • 183
  • 1
  • 7
  • 18

3 Answers3

1

1) For dropdown list use select

var dropdownlist = $("#dropdownlist").data("kendoDropDownList");
dropdownlist.select(1);

(There are different options how to select specific item.)

Grid edit event example with your drop down list,

 edit: function(e) {
    if (e.model.isNew()) {
        var ddl = e.container.find("input[name=id]").data("kendoDropDownList");
        ddl.select(1);
    }
  } 

2) This is how to use custom editor in your grid, just in case your dropdown is not populated yet.

3) You could also use OptionLabel

Vojtiik
  • 2,558
  • 1
  • 17
  • 21
  • In my case dropdownlist.select(1); set the value but soon after in kendo.all.min.js value get cleared. We are using kendo v2017.2.621 version. Any help is highly appreciated. – Abhi Oct 27 '22 at 11:20
0

Try this, hope it will work:
Simply add it in your chain. .Value("YOUR_VALUE").

Rohit Paul
  • 336
  • 1
  • 3
  • 13
  • not sure what you mean. so it reads e.container.find("input[name=lender]").data("kendoDropDownList").value(lender).Value(lender); – user2012783 Oct 15 '13 at 16:13
  • I think it is case sensitive .value wont work. Replace it with. Value. – Rohit Paul Oct 15 '13 at 16:26
  • thanks but i tried that and it throws a type issue error. .value() does set the value of the dropdownlist. the problem is the when you click to insert it posts a blank value because it doesn't now its change. where as my text inputs are set using e.container.find("input[name=policy]").val(lender_policy).change(); which has the change() function which must tell the grid something has changed. – user2012783 Oct 15 '13 at 17:11
  • By using val(lender_policy) you are setting some value into the dropdown, to later save it you should again use. .val() or .text() to find out the selected value. – Rohit Paul Oct 15 '13 at 17:52
  • thanks again. i think your getting confused. i can use 'e.container.find("input[name=policy]").val(lender_policy).change()' to set the text input of a form and it posts fine. i cant use that to set a dropdownlist because it doesnt work so i used 'e.container.find("input[name=lender]").data("kendoDropDownList").value(lender)'. but this sets the dropdownlist value but posts empty data because the grid doesn't notice the change. – user2012783 Oct 15 '13 at 19:31
0

If .Value("YOUR_VALUE") does not work(In some older kendo versions from 2012). Please use .HtmlAttributes(new { value = "YOUR_VALUE" }) instead

int-i
  • 661
  • 1
  • 12
  • 28