Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/KeudellCoding/Blazor.AdvancedBlazorSelect2

Simple wrapper for Select2 with full support of databases and custom web APIs.
https://github.com/KeudellCoding/Blazor.AdvancedBlazorSelect2

blazor blazor-component component html-select select2 selector

Last synced: 3 months ago
JSON representation

Simple wrapper for Select2 with full support of databases and custom web APIs.

Lists

README

        

# Blazor.AdvancedBlazorSelect2

## Installation
1. Install the NuGet package `KeudellCoding.Blazor.AdvancedBlazorSelect2`.
2. Add the following lines to _Host.cshtml (in the head tag)
```html

```
3. Make sure [jQuery](https://jquery.com/download/) is installed.
4. Add the following lines to _Imports.razor
```csharp
@using KeudellCoding.Blazor.AdvancedBlazorSelect2
```

## Usage Example
```csharp
@page "/"
@inject IMemoryCache __MemoryCache
@inject ApplicationDbContext __DbContext

@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 SelectedItems { get; set; }

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

private async Task> filterFunction(DbSet 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. `GetElementById` must be set manually because the process also depends on the data source used.