The following example consists of two AutoComplete editors that bind to Model properties - OrganizarionName and OrganizationNumber. When the user types the name of an organization in the first AutoComplete, if the searched name appears as an option and the user selects it, then the second AutoComplete is filtered automatically based on the selected option in the first one and the respective option (the organization number) is selected. Also, when the user types an organization number (the second AutoComplete), the organization name is selected automatically in the first AutoComplete editor.
Define the two AutoCompletes bound to the Model properties and configure them to use server filtering.
Use the Data() method of the DataSource to pass the selected option of the AutoComplete through the Read request of the cascaded AutoComplete. For example, when the user selects an organization name (the first AutoComplete), the name will be sent to the server through the Read request of the OrganizationNumber AutoComplete.
<script>functiononAdditionalData1(){let selectedOrganizationNumber =$("#OrganizationNumber").data("kendoAutoComplete").value();// Get the currently selected option of the OrganizationNumber AutoComplete, if anyreturn{text:$("#OrganizationID").val(),// Pass the search entry of the AutoComplete (the ServerFiltering() is enabled).Number: selectedOrganizationNumber !=null? selectedOrganizationNumber :""// Pass the selected OrganizationNumber to the server};}functiononAdditionalData2(){let selectedOrganization =$("#OrganizationID").data("kendoAutoComplete").value();return{text:$("#OrganizationNumber").val(),Name: selectedOrganization !=null? selectedOrganization :""// Pass the selected OrganizationName to the server.};}</script>
Filter the data server-side based on the selected AutoComplete option.
<script>functiononSelectOrganizationName(e){let selectedOption = e.sender.value();// Get the selected organization name.var organizationNumbersControl =$("#OrganizationNumber").data("kendoAutoComplete");// Get a reference to the 2nd AutoComplete that holds the organization number.setTimeout(function(){if(selectedOption !=null&& organizationNumbersControl.value()!= selectedOption){
organizationNumbersControl.dataSource.fetch(function(){// Make a request to the server to get the Organization numbers datalet data =this.data();// The server returns the filtered data.if(data.length==1){
organizationNumbersControl.value(data[0].Number);// Set the organization number value.
organizationNumbersControl.trigger("change");}});}},100);}functiononSelectOrganizationNumber(e){let selectedOption = e.sender.value();var organizationNamesControl =$("#OrganizationID").data("kendoAutoComplete");setTimeout(function(){if(selectedOption !=null&& organizationNamesControl.value()!= selectedOption){
organizationNamesControl.dataSource.fetch(function(){let data =this.data();if(data.length==1){
organizationNamesControl.value(data[0].Name);
organizationNamesControl.trigger("change");}});}},100);}</script>