How to disable default value in Kendo dropdownlist?

Asked

Viewed 177 times

4

I have a Kendo grid and I’m creating a template for editing the data presented on the grid, but I’m having problems with the code below...
This is part of the code of my template:

<script id="popup_editor" type="text/x-kendo-template">

<div class="k-edit-label">
   <label for="Sexo">Sexo</label>
</div>

<input name="Sexo"
   data-bind="value:Sexo"
   data-value-field="sexoValue"
   data-text-field="sexoName"
   data-source="sexoDropDownDataSource"
   data-role="dropdownlist" />

</script>

This is my script to fill the dropdownlist with the necessary data:

sexoDropDownDataSource = new kendo.data.DataSource({
                autoBind: false,
                dataTextField: "sexoName",
                dataValueField: "sexoValue",
                data: [
                    { sexoName: "Masculino", sexoValue: "M" },
                    { sexoName: "Feminino", sexoValue: "F" }
                ]
            });

As you can see it is all right, and the code is working perfectly bringing the value that is on the grid, but the problem is that even with the autoBind receiving the value false the dropdownlist is coming with the first option always selected (in case masculino), that is, when the data of a person of sex feminino is edited, the dropdownlist shows by default the value that came from the grid (feminino), but when it is expanded the two values selected are displayed. How can I resolve this?

Look what I’m talking about:
Resultado

  • I searched the documentation and I couldn’t find anything on how to disable this, however, as an alternative, you can set a default value using the property value, see this example.

  • 'Cause you’re my friend, thank you very much for your commitment to help me, I haven’t found anything yet either. The problem is that in my case the kendoDropDownList is created within the x-kendo-template and I can’t create such an object in javascript to be placed there, just the DataSource. I’m studying a little of this x-kendo-template, it is not possible that there is no property that can do this.

  • Another thing, is that actually I would not like to come with a default value marked, but on the contrary, I would like only the value that is on the grid to be marked.

  • Any chance you can play this in a demo?

1 answer

-1

  • Well, I guess I didn’t really explain the question... I need Dropdown not to come with selected value, just what came from Grid. The problem is that the feminine value of the grid is coming, but the Dropdown always leaves selected the first element of it that in the case is masculine, then ends up being as in the image..

  • then use the Ondatabinding event to leave only the value that is not selected with the white background (#ffffff), take a look: http://stackoverflow.com/questions/2609344/how-to-format-individual-dropdownlist-items-color-etc-during-ondatabinding-e

Browser other questions tagged

You are not signed in. Login or sign up in order to post.