Good day.
I am trying to make a filter to a ListBox, but I have not gotten it to work for me, could you please help
the listBox
@(Html.Kendo().ListBox()
.Name("lstBuscarMenu")
.HtmlAttributes(new { style = "width:100%;height:700px;"})
.DataTextField("Nombre")
.TemplateId("customer-item-template")
.BindTo(ViewBag.Menus)
)
the planitlla
<script id="customer-item-template" type="text/x-kendo-template">
<span class="k-state-default"><strong>#: data.Nombre #</strong><p style="font-size:0.6rem;">#: data.Seccion #</p></span>
</script>
the javascript
var dataSourceMenu = null;
$("#txtBuscarMenu").keyup(function(e) {
var texto = $("#txtBuscarMenu").val();
var grid = $("#lstBuscarMenu").data("kendoListBox");
if (dataSourceMenu === null) {
dataSourceMenu = grid.dataItems();
}
if (texto.length === 0) {
grid.setDataSource(dataSourceMenu);
}
else {
grid.setDataSource(dataSourceMenu.find(x => x.Nombre.indexOf(texto) > -1));
}
});
best regards