KeudellCoding.Blazor.AdvancedBlazorSelect2 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package KeudellCoding.Blazor.AdvancedBlazorSelect2 --version 1.0.0
NuGet\Install-Package KeudellCoding.Blazor.AdvancedBlazorSelect2 -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="KeudellCoding.Blazor.AdvancedBlazorSelect2" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add KeudellCoding.Blazor.AdvancedBlazorSelect2 --version 1.0.0
#r "nuget: KeudellCoding.Blazor.AdvancedBlazorSelect2, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install KeudellCoding.Blazor.AdvancedBlazorSelect2 as a Cake Addin
#addin nuget:?package=KeudellCoding.Blazor.AdvancedBlazorSelect2&version=1.0.0

// Install KeudellCoding.Blazor.AdvancedBlazorSelect2 as a Cake Tool
#tool nuget:?package=KeudellCoding.Blazor.AdvancedBlazorSelect2&version=1.0.0

Blazor.AdvancedBlazorSelect2

Installation

Add the following lines to _Host.cshtml (in the head tag)

<script src="_content/KeudellCoding.Blazor.AdvancedBlazorSelect2/Select2JsInterop.js" type="text/javascript" language="javascript"></script>
<script src="_content/KeudellCoding.Blazor.AdvancedBlazorSelect2/lib/select2/js/select2.full.min.js" type="text/javascript" language="javascript"></script>
<link href="_content/KeudellCoding.Blazor.AdvancedBlazorSelect2/lib/select2/css/select2.min.css" rel="stylesheet" />

Add the following lines to _Imports.razor

@using KeudellCoding.Blazor.AdvancedBlazorSelect2

Usage Example

@page "/"
@inject IMemoryCache __MemoryCache
@inject ApplicationDbContext __DbContext

<Select2 TItem="ExampleItemForm"
         IdSelector="c => c.Id.ToString()"
         TextSelector="c => c.Text"
         FilterFunction="filterFunction"
         GetElementById="async (items, id, token) => await items.SingleOrDefaultAsync(i => i.Id.Equals(id), token)"
         Datasource="__DbContext.ExampleItems.AsQueryable()"
         Value="@SelectedItems"
         Cache="__MemoryCache"
         Multiselect="false" />


@code {
    public class ExampleItemForm {
        public Guid Id { get; set; }
        public string Text { get; set; }

        public ExampleItemForm(Guid id, string text) {
            Id = id;
            Text = text;
        }
    }

    //======================================================

    public List<ExampleItemForm> SelectedItems { get; set; }

    //======================================================

    private async Task<List<ExampleItemForm>> filterFunction(IQueryable<ExampleItemForm> allItems, string filter, CancellationToken token) {
        return await allItems.Where(i => i.Text.StartsWith(filter)).ToListAsync();
    }
}

Notes

  1. It is ensured that the SelectedItems list contains only one item if Multiselect is set to false.
  2. As soon as SelectedItems is edited manually, StateHasChanged(); should be executed.
  3. Datasource must contain a list of the type IQueryable. Static lists can also be used, but these must be converted with the addition .AsQueryable();.
  4. GetElementById must be set manually, because in case of a database connection functions in LINQ are not supported.
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.3.0 18,062 9/4/2020
1.2.0 1,023 9/3/2020
1.1.0 954 9/1/2020
1.0.0 1,031 8/31/2020