Unplanned
Last Updated: 03 Oct 2024 08:30 by Roberto
Roberto
Created on: 02 Oct 2024 08:05
Category: UI for Blazor
Type: Feature Request
3
Expose current data for the select (dropdown) components when using OnRead

Please expose the current data of the data bound select components when using OnRead. This will spare the need to cache data for the second time in-memory, or make a database request, or search by non-ID value when the app needs to obtain the full data item(s) for given component value(s).

This feature request is applicable to:

  • AutoComplete
  • ComboBox
  • DropDownList
  • MultiColumnComboBox
  • MultiSelect

 

3 comments
Roberto
Posted on: 02 Oct 2024 11:05
Roberto
Posted on: 02 Oct 2024 10:42

An implementation of this that will not allow the data items retrieved to be modified could be as follows:

public TItem GetSelectedItem()
{
    return SelectedDataItem != null && SelectedDataItem.DataItem != null ? (TItem)SelectedDataItem.DataItem.Clone() : default(TItem);
}

public ReadOnlyCollection<TItem> GetAllReadonlyDataItems()
{
    List<TItem> dataItems = new List<TItem>();

    foreach (var item in DataItems)
    {
        if (item.DataItem is TItem dataItem)
        {
            var clonedDataItem = (TItem)dataItem.Clone();
            dataItems.Add(clonedDataItem);
        }
    }

    return new ReadOnlyCollection<TItem>(dataItems);
}