0
votes

Background: I have a kendo multiselect that gets populated with emails based on the values of a kendo dropdown. I also need to use the multiselect to 'search' for additional emails through our employee api. Then as i search and select new values to be added to the 'selected values' portion of the multiselect i want to be able to go back and see the initial populated values without the searched values.

Disclaimer: I can get all of this to work except the searched values get 'added' to the datasource which I dont want. Think of a temporary datasource when searching. So when i go to look through the initial populated values, the returned search vales are appended to the datasource values. Again, I do not want this.

enter image description here

enter image description here

enter image description here

CODE:

<div class="row display-row">
        <div class="col-lg-4 col-md-4 col-sm-4 col-xs-12">
            <h4>Location Group:</h4>
                @(Html.Kendo().DropDownList()
                .Name("weatherLocGroupNameDropDown")
                .HtmlAttributes(new { style = "width:100%" })
                .OptionLabel("Select location group...")
                .DataTextField("LocationGroupName")
                .DataValueField("LocationGroupId")
                .DataSource(source =>
                {
                    source.Read(read =>
                    {
                        read.Action("getLocationGroupNames", "Base");
                    });
                })
            )
        </div>
        <div class="col-lg-4 col-md-4 col-sm-4 col-xs-12">
            <h4>Location:</h4>
            @(Html.Kendo().DropDownList()
                .Name("weatherLocNameDropDown")
                .HtmlAttributes(new { style = "width:100%" })
                .OptionLabel("Select location...")
                .DataTextField("LocationName")
                .DataValueField("LocationId")
                .DataSource(source =>
                {
                    source.Read(read =>
                    {
                        read.Action("getLocationNamesFilteredByLocationGroup", "Base")
                            .Data("filterLocation");
                    })
                    .ServerFiltering(true);
                })
                .Enable(false)
                .AutoBind(false)
                .Events(ev => ev.Change("populateLocGrpEmails")) 
                .CascadeFrom("weatherLocGroupNameDropDown")
            )
        </div>


    <div class="row display-row">
        <div class="col-lg-8 col-md-8 col-sm-8 col-xs-12">
            @(Html.Kendo().MultiSelect()
                .Name("recipientMultilist")
                .Placeholder("Recipient(s)")
                .AutoBind(false)
                .Enable(false)
                .HtmlAttributes(new { style = "width:100%" })
                .DataTextField("EmailName")
                .DataValueField("EmailId")
            .Events(ev => ev.Filtering("searchEmails"))
            )
        </div>
    </div>


function searchEmails() {
    var searchText = $("#recipientMultilist").data('kendoMultiSelect').input.val();

    searchText = searchText.trim();
    if (searchText.length >= 3 && searchText != undefined && searchText != "") {
        $.ajax(
            {
                url: "@Url.Action("getRecipientEmails", "Base")",
                data: { searchTerm: searchText },
                type: "GET",
                dataType: "json",
                async: false,
                success: function (searchEmail) {
                    if (searchEmail.length > 0) {
                        for (var i = 0; i < searchEmail.length; i++) {
                            $('#recipientMultilist').data("kendoMultiSelect").dataSource.add({
                                EmailName: searchEmail[i].EmailName,
                                EmailId: searchEmail[i].EmailId
                            });
                        }
                    }
                }, error: function (searchEmailErr) { console.log('searchEmailErr: ', searchEmailErr); }
            })
        }
}

function getLocationGroupEmails() {
    return {
        LocationGroupId: $("#weatherLocGroupNameDropDown").data("kendoDropDownList").value()
    }
}

function filterLocation() { 
    return {
        LocationGroupId: $("#weatherLocGroupNameDropDown").data("kendoDropDownList").value()
    };
}

function populateLocGrpEmails() {
    $("#recipientMultilist").data("kendoMultiSelect").enable();
    tempMultiListStorage = [];

    var locationText = $("#weatherLocNameDropDown").data('kendoDropDownList').text();
    var locationGroupId = $("#weatherLocGroupNameDropDown").data('kendoDropDownList').value()

    //get all emails associated with the location group and inserts into the recipientMultilist
    $.ajax(
        {
            url: "@Url.Action("getEmailFilteredByLocationGroup", "Base")",
            data: { LocationName: locationText, LocationGroupId: locationGroupId },
            type: "GET",
            dataType: "json",
            async: false,
            success: function (filteredEmail) {
                if (filteredEmail.length > 0) {
                    for (var i = 0; i < filteredEmail.length; i++) {
                        $('#recipientMultilist').data("kendoMultiSelect").dataSource.add({
                            EmailName: filteredEmail[i].EmailName,
                            EmailId: filteredEmail[i].EmailId
                        });

                        tempMultiListStorage.push({
                            EmailName: filteredEmail[i].EmailName,
                            EmailId: filteredEmail[i].EmailId })
                    }
                }
            }, error: function (filteredEmailErr) { console.log('filteredEmailErr: ', filteredEmailErr); }
        })

    var multiselect = tempMultiListStorage



    //"selects" the record that matches the location
    var dropdownlist = $("#recipientMultilist").getKendoMultiSelect();
    dropdownlist.value(locationText)
    dropdownlist.trigger("change");
}

I do know that this code in searchEmails

    $('#recipientMultilist').data("kendoMultiSelect").dataSource.add({
                            EmailName: searchEmail[i].EmailName,
                            EmailId: searchEmail[i].EmailId
                        });

is adding the values to the multiselect but thats there so i can at least test a few other things. Again, i am looking to 'see' the searched values, select the search values but not make them part of the 'datasource' by adding them.

I hope this was clear haha.

1

1 Answers

0
votes

Can you give this a try and see if it works:

$("#multiselect").kendoMultiSelect({
  select: function(e) {
      e.preventDefault();
  }
});