Kendo UI - Multiselect with remote data source

Asked

Viewed 93 times

1

I’ve been racking my brain with multiselect of Kendo UI. Every time I return the list with my information action, the plugin fails to understand the information and returns me the following error: Cannot read property 'value' of undefined. I have tried to transform into javascript array, Json, and will not at all. Follow the javascript code of the plugin:

//Aplicar o filtro de Emails no campo de destinatários
$("#select-destinatarios").kendoMultiSelect({
    placeholder: "Selecione os destinatários...",
    dataTextField: "Email",
    dataValueField: "Id",
    autoBind: false,
    minLength: 3,
    filtering: function (e) {
        var filter = e.filter;
        if (!filter.value) {
            //prevent filtering if the filter does not value
            e.preventDefault();
        }
    },
    dataSource: {
        serverFiltering: true,
        transport: {
            read: {
                url: '../Alertbox/CarregarDestinatarios',
                dataType: 'json',
                data: function () {
                    return {
                        filtro: $("#select-destinatarios").data('kendoMultiSelect').input.val(), tipoDestinatario: $("#slc-tipo-envio").val()
                    };
                }
            }
        }
    }
});

On the server return a List<object> with the properties Email and Id as shown in the code below:

if (!String.IsNullOrEmpty(filtro))
{
    Usuario usuario = new Usuario();
    Alertas = usuario.FiltroDestinatario(filtro, Id, tipoDestinatario);
}
else
{
    Alertas = new Dictionary<string, string>();
}

foreach(var item in Alertas)
{
    ListaFinal.Add(new
    {
        Email = item.Key,
        Id = item.Value
    });
}

return Json(ListaFinal, JsonRequestBehavior.AllowGet);

The problem is that after so much trying it worked with 1 record. When brought more, presented the above error message and even bringing only one record after that, the message persisted.

Can someone help me?

  • the function of the data property sends to the server and returns the result for the Source data. Strangely, it works one thing, not another, for everything. And that without changing a line of code. Maybe it is some confusion that he is doing internally since the system is using several plugins. Apparently it is working now. Thank you.

  • I think if you harvest data: function (data) { em veze de data: function () { and give a console.log(data); you will be able to see the return of your server.

No answers

Browser other questions tagged

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