I have the following set up.
<TelerikMultiSelect Data="@lstXfers" @ref="@Xrefs"
@bind-Value="@lstSelectedXfers"
TextField="FermentationName" ValueField="FermentationXferId"
Width="250px" ClearButton="true" AutoClose="false"
OnBlur="OnXferBlur"
OnRead="OnXferRead"
Filterable = "true" FilterOperator="StringFilterOperator.Contains"
/>
I am doing custom filter to allow the user to enter a filter and, when the control loses focus, if the typed in filter is an exact match to one of the available items, then the typed in item will be added.
Everything works great, with one exception. I can't seem to clear the Request.Filters Telerik.DataSource.FilterDescriptor collection.
private FilterDescriptor filter;
protected void OnXferRead(MultiSelectReadEventArgs args)
{
if (args.Request.Filters.Count() > 0)
{
filter = args.Request.Filters[0] as Telerik.DataSource.FilterDescriptor;
var q1 = from a in db.Fermentations
where a.IsActive == true && a.SiteId == appData.SiteId
select new FermentationXferModel()
{
FermentationName = a.FermentationName,
FermentationXferId = a.FermentationId
};
q1 = q1.OrderBy(a => a.FermentationName).Distinct();
lstXfers = q1.ToList();
args.Data = lstXfers;
var lstSelectedItemsToExclude = (from a in lstXfers
where lstSelectedXfers.Contains(a.FermentationXferId)
select a).ToList();
var filterItems = (from a in lstXfers
where !a.FermentationName.ToLower().StartsWith(filter.Value.ToString().ToLower())
select a).Except(lstSelectedItemsToExclude).ToList();
args.Data = (from a in (List<FermentationXferModel>)args.Data select a).Except(filterItems);
}
else
args.Data = lstXfers;
}
public void OnXferBlur()
{
if (filter != null)
{
FermentationXferModel filterEntry;
filterEntry = (from a in lstXfers
where a.FermentationName.ToLower() ==
filter.Value.ToString().ToLower()
select a).FirstOrDefault();
if (filterEntry != null)
{
// mark it as selected
filterEntry.Selected = true;
// create a new list to force a refresh.
// this thing doesn't support observablecollections.
List<int> lst = new List<int>(lstSelectedXfers);
// add the matching entry
lst.Add(filterEntry.FermentationXferId);
//copy the list to the bound variable
lstSelectedXfers = new List<int>(lst);
// Clean up the typed in filter
Task.Run(async () => await jsRuntime.InvokeVoidAsync("clearMultiselectInput"));
}
else
{
var q1 = from a in db.Fermentations
where a.IsActive == true && a.SiteId == appData.SiteId
select new FermentationXferModel()
{
FermentationName = a.FermentationName,
FermentationXferId = a.FermentationId
};
q1 = q1.OrderBy(a => a.FermentationName).Distinct();
lstXfers = q1.ToList();
Xrefs.Data = lstXfers;
}
}
}
And teh js:
function clearMultiselectInput()
{
var inputs = document.querySelectorAll(".k-multiselect .k-input-inner");
inputs.forEach(e => e.value = "")
}
Ideally, in the OnBlur handler if the private FilterDescriptor filter property is not null, then I want to clear it.
How???
Thanks... Ed