QuickGrid can show data from three main sources:
This is the simplest option when working with small amounts of data, up to a few hundred items.
Simply obtain your data through whatever means you want (e.g., a call to a JSON API endpoint, or a direct database query),
and then use the AsQueryable
extension method to make it suitable for in-memory querying. Pass this value
as the grid's Items
parameter.
Argentina | 0 | 1 | 2 | 3 |
Armenia | 0 | 2 | 2 | 4 |
Australia | 17 | 7 | 22 | 46 |
Austria | 1 | 1 | 5 | 7 |
Azerbaijan | 0 | 3 | 4 | 7 |
Bahamas | 2 | 0 | 0 | 2 |
Bahrain | 0 | 1 | 0 | 1 |
Belarus | 1 | 3 | 3 | 7 |
Belgium | 3 | 1 | 3 | 7 |
Bermuda | 1 | 0 | 0 | 1 |
Botswana | 0 | 0 | 1 | 1 |
Brazil | 7 | 6 | 8 | 21 |
Bulgaria | 3 | 1 | 2 | 6 |
Burkina Faso | 0 | 0 | 1 | 1 |
Canada | 7 | 6 | 11 | 24 |
Chinese Taipei | 2 | 4 | 6 | 12 |
Colombia | 0 | 4 | 1 | 5 |
Côte d'Ivoire | 0 | 0 | 1 | 1 |
Croatia | 3 | 3 | 2 | 8 |
Cuba | 7 | 3 | 5 | 15 |
Czech Republic | 4 | 4 | 3 | 11 |
Denmark | 3 | 4 | 4 | 11 |
Dominican Republic | 0 | 3 | 2 | 5 |
Ecuador | 2 | 1 | 0 | 3 |
Egypt | 1 | 1 | 4 | 6 |
Estonia | 1 | 0 | 1 | 2 |
Ethiopia | 1 | 1 | 2 | 4 |
Fiji | 1 | 0 | 1 | 2 |
Finland | 0 | 0 | 2 | 2 |
France | 10 | 12 | 11 | 33 |
Georgia | 2 | 5 | 1 | 8 |
Germany | 10 | 11 | 16 | 37 |
Ghana | 0 | 0 | 1 | 1 |
Great Britain | 22 | 21 | 22 | 65 |
Greece | 2 | 1 | 1 | 4 |
Grenada | 0 | 0 | 1 | 1 |
Hong Kong, China | 1 | 2 | 3 | 6 |
Hungary | 6 | 7 | 7 | 20 |
India | 1 | 2 | 4 | 7 |
Indonesia | 1 | 1 | 3 | 5 |
Ireland | 2 | 0 | 2 | 4 |
Islamic Republic of Iran | 3 | 2 | 2 | 7 |
Israel | 2 | 0 | 2 | 4 |
Italy | 10 | 10 | 20 | 40 |
Jamaica | 4 | 1 | 4 | 9 |
Japan | 27 | 14 | 17 | 58 |
Jordan | 0 | 1 | 1 | 2 |
Kazakhstan | 0 | 0 | 8 | 8 |
Kenya | 4 | 4 | 2 | 10 |
Kosovo | 2 | 0 | 0 | 2 |
Kuwait | 0 | 0 | 1 | 1 |
Kyrgyzstan | 0 | 2 | 1 | 3 |
Latvia | 1 | 0 | 1 | 2 |
Lithuania | 0 | 1 | 0 | 1 |
Malaysia | 0 | 1 | 1 | 2 |
Mexico | 0 | 0 | 4 | 4 |
Mongolia | 0 | 1 | 3 | 4 |
Morocco | 1 | 0 | 0 | 1 |
Namibia | 0 | 1 | 0 | 1 |
Netherlands | 10 | 12 | 14 | 36 |
New Zealand | 7 | 6 | 7 | 20 |
Nigeria | 0 | 1 | 1 | 2 |
North Macedonia | 0 | 1 | 0 | 1 |
Norway | 4 | 2 | 2 | 8 |
People's Republic of China | 38 | 32 | 18 | 88 |
Philippines | 1 | 2 | 1 | 4 |
Poland | 4 | 5 | 5 | 14 |
Portugal | 1 | 1 | 2 | 4 |
Puerto Rico | 1 | 0 | 0 | 1 |
Qatar | 2 | 0 | 1 | 3 |
Republic of Korea | 6 | 4 | 10 | 20 |
Republic of Moldova | 0 | 0 | 1 | 1 |
ROC | 20 | 28 | 23 | 71 |
Romania | 1 | 3 | 0 | 4 |
San Marino | 0 | 1 | 2 | 3 |
Saudi Arabia | 0 | 1 | 0 | 1 |
Serbia | 3 | 1 | 5 | 9 |
Slovakia | 1 | 2 | 1 | 4 |
Slovenia | 3 | 1 | 1 | 5 |
South Africa | 1 | 2 | 0 | 3 |
Spain | 3 | 8 | 6 | 17 |
Sweden | 3 | 6 | 0 | 9 |
Switzerland | 3 | 4 | 6 | 13 |
Syrian Arab Republic | 0 | 0 | 1 | 1 |
Thailand | 1 | 0 | 1 | 2 |
Tunisia | 1 | 1 | 0 | 2 |
Turkey | 2 | 2 | 9 | 13 |
Turkmenistan | 0 | 1 | 0 | 1 |
Uganda | 2 | 1 | 1 | 4 |
Ukraine | 1 | 6 | 12 | 19 |
United States of America | 39 | 41 | 33 | 113 |
Uzbekistan | 3 | 0 | 2 | 5 |
Venezuela | 1 | 3 | 0 | 4 |
When using in-memory IQueryable, there's no limit on the kinds of sorting or filtering you can do, because it's all computed in memory. However, you don't get the benefit of database indexes for the in-memory operations, so this can be a performance bottleneck. If you're working with larger data set, consider a different data source.
This is the simplest and best-performing option if you're using EF Core:
EF Core's DataContext
gives you a DbSet
property for each table in your database. Simply supply this
as the grid's Items
parameter:
@inject ApplicationDbContext MyDbContext
<QuickGrid Items="@MyDbContext.People">
...
</QuickGrid>
You may also use any EF-supported LINQ operator to filter the data before passing it:
@inject ApplicationDbContext MyDbContext
<QuickGrid Items="@MyDbContext.Documents.Where(d => d.CategoryId == currentCategoryId)">
...
</QuickGrid>
QuickGrid recognizes EF-supplied IQueryable
instances and knows how to resolve queries asynchronously for efficiency.
For this to work, you'll need to reference the Microsoft.AspNetCore.Components.QuickGrid.EntityFrameworkAdapter
package
and call AddQuickGridEntityFrameworkAdapter
in your Program.cs
file:
builder.Services.AddQuickGridEntityFrameworkAdapter();
If you forget to do this, you'll get an error to remind you.
If you're using Blazor WebAssembly, it's very common to fetch data from a JSON API on a server. If you want to
fetch only the data that's needed for the current page/viewport and apply any sorting or filtering rules on the
server, you can use the ItemsProvider
parameter.
You can also use ItemsProvider
with Blazor Server if it needs to query an external endpoint, or in any
other case where your requirements aren't covered by an IQueryable
.
To do this, supply a callback matching the GridItemsProvider<TGridItem>
delegate type, where TGridItem
is the type of data displayed in the grid. Your callback will be given a parameter of type GridItemsProviderRequest<TGridItem>
which specifies the start index, maximum row count, and sort order of data to return. As well as returning the matching items, you need
to return a totalItemCount
so that paging or virtualization can work.
Here is an example of connecting a grid to the public OpenFDA Food Enforcement database.
ID | State | City | Company | Status |
---|
Total: 25333 results found
This particular endpoint doesn't support sorting, so none of the columns are marked as sortable. However it does support skip
and
limit
parameters, so we can enable virtualization and scroll quickly through tens of thousands of records.
Sometimes you might know that the data source's contents will have changed. For example, the user may have
saved some changes that will affect the data, or they might have changed the current query parameters. In
any such case, you can call the grid's RefreshDataAsync
method:
<QuickGrid ... @ref="myGrid">
...
</QuickGrid>
@code {
QuickGrid<MyDataType> myGrid;
async Task HandleSomeEvent()
{
...
// We can force the grid to reload the current data
await myGrid.RefreshDataAsync();
}
}