2

I have a KendoComboBox, in MVC mode, these Combo load ok a list of values.

Now, I need load these ComboBox but I need you to automatically preselect a certain value only if It exist in the list of values, if not find the value, preselect other value.

@(Html.Kendo().ComboBox()
    .Name("Test")
    .HtmlAttributes(new { style = "width:100%" })
    .Placeholder("Seleccione")
    .DataTextField("name")
    .DataValueField("Id")
    .Filter("contains")        
    .DataSource(source =>
    {    
        source.Read(read =>
        {
            read.Action("CargaCombo", "Test");                   
        });               
    })
    .Value("TODOS")
    .Suggest(true)
)

I tried using Events as "Find", read using jQuery the data, but I can't. Any Help? For Example I Tried this other post, How to retrieve all data of a kendo ui dropdown list? but It not work for me, maybe as I use KendoComboBox and not KendoDropDown.

thanks!

Community
  • 1
  • 1
Hernaldo Gonzalez
  • 1,977
  • 1
  • 21
  • 32

1 Answers1

1

Finally, I use DataBoundEvent:

<script type="text/javascript">
    function onDataBound() {        
        var user = $.trim($(".userlogged").text());    
        var encontrado = false;           
        var elementos = $("#Test").data("kendoComboBox").dataSource.data();
        $.each(elementos, function (index, value) {
            if (value.Nombre == user) {
                $("#Test").data("kendoComboBox").value(user);
                encontrado = true;
                return;
            }
        });

        if (!encontrado) {
            $("#Test").data("kendoComboBox").value(0);
        }
    }    
</script>

And add the Event:

.Events(e =>
{
    e.DataBound("onDataBound");
})
Nic
  • 12,220
  • 20
  • 77
  • 105
Hernaldo Gonzalez
  • 1,977
  • 1
  • 21
  • 32