Scopes
Filter the index page with tabs
Introduction
Scopes are tabs displayed above the grid that allows you to filter records based on predefined filters.


Call EnableScopes(), then call the Add() method on the scope builder to add the different scopes. The example below adds four scopes to the bookings grid, and selects All by default:
resource.Index(index =>
{
index.EnableScopes(scopes =>
{
scopes.Add("all", "All");
scopes.Add("pending", "Pending", booking => booking.Status == BookingStatus.Pending);
scopes.Add("confirmed", "Confirmed", booking => booking.Status == BookingStatus.Confirmed);
scopes.Add("cancelled", "Cancelled", booking => booking.Status == BookingStatus.Cancelled);
scopes.DefaultScope = "all";
});
});The Add() methods takes the following arguments:
- The scope's
id, which is uses in the query string parameter, for example?scope=pending. Each scope for a specific resource must have a unique id. - The text displayed on the scope's tab.
- A filter expression, which can be omitted for a scope that must display all records.
Setting the default scope
DefaultScope sets the scope that is selected when the user has not explicitly selected a scope. Without a default scope, no tab is selected, and the grid displays every record until the user selects a scope.
DefaultScope must be the id of a scope you've added. If it isn't, StellarAdmin ignores it and reports a configuration problem.
Combining scopes with search
StellarAdmin applies both the scope's filter and the search, so searching on the Pending tab searches only the pending bookings.
Scopes in a custom data source
When a resource uses a custom data source, add each scope without a filter expression, for example scopes.Add("pending", "Pending"). StellarAdmin passes the id of the selected scope when calling the ListAsync() method. You can use this to apply the correct filter logic.