Skip to content

Reference

The Shift Grid fetches data and prepares it in a format that can be easily integrated into a Data Table.

Grid

The Grid (ShiftSoftware.ShiftGrid.Core.Grid) can be initialized by calling the ToShiftGridAsync or ToShiftGrid extension methods on an IQueryable.

The Grid contains below properties.

Property Description
DataPageIndex int
The current page index of the paginated data.
DataPageSize int
The Number of Items (Or number of rows) per Page.
DataCount int
The total count of the data (The Unpaginated Count).
Data List<T>
This is the actual data that's fetched from Database.
Aggregate T2
Aggregated Data. This is available if SelectAggregate extension method is used.
Sort List<GridSort>
The list of Fields that the Data is sorted by.
StableSort GridSort
The mandatory Stable Sort that the data is sorted by.
Learn more about Stable Sorting
Filters List<GridFilter>
The list of filters that the data is filtered by.
Columns List<GridColumn>
The column defnition of the Dataset that contains below:
HeaderText, Field, Visible, and Order.
Pagination GridPagination
Information about the pagination area.
BeforeLoadingData DateTime (UTC)
The timestamp just before making the database call(s)
AfterLoadingData DateTime (UTC)
The timestamp just after the data is finished loading from database

GridConfig

The ToShiftGridAsync and ToShiftGrid extension methods accept a GridConfig. This is used to control the Grid. Like setting the page size, index, sorting, filters ...etc. Below are the properties.

Property Description
DataPageIndex int
Sets the page index of the paginated data.
DataPageSize int
Sets the Page Size (Or number of items/rows per page) that's fetched from the Database.
Defaults to 20
Sort List<GridSort>
A list of Fields to sort the Data by. The order of the items in the list is important. It'll be passed to the database in the same order.
Filters List<GridFilter>
A list of filters to filter the Data by.
Columns List<GridColumn>
Mainly used to hide fields (Set Visible to false).
Hidden fields are also excluded it in the SQL Query. And if there are table joins, the joining will be omitted.
Pagination PaginationConfig
Adjusts the pagination area.
ExportConfig ExportConfig
Can be used to set the Export flag and the CSV Delimiter.

GridSort

Property Description
Field string
The field (Column) for sorting the Data.
SortDirection SortDirection
An enum indicating the direction of the Sort.
SortDirection.Ascending or SortDirection.Descending

GridFilter

We use System.Linq.Dynamic.Core under the hood for applying filters.

Property Description
Field string
The field that the filter is applied on.
Operator string
The filter operator. Can be one of the below:
=, !=, >, >=, <, <=, Contains, In, NotIn, StartsWith, EndsWith
Value object
The value for filtering (or the search term).
OR List<GridFilter>
A list of GridFilter that will be ORed with the crreunt filter.

GridColumn

Property Description
HeaderText string
The optional Header Text (or Display Text) for the Column. Useful to pass it down to the client from the Server.
Field string
The Field Name as specified on the LINQ Select statement.
Visible bool
When set to false, the field will be excluded in the generated SQL. If the field comes from a table join. The join is also omitted.

Hidng columns only work when .Select is used on the data.
If .Select is not used, a ColumnHidingException will be thrown.
Order int
The order of the Column on the Data Grid.

GridPagination

This is purely there to help the client while setting up the pagination area. You might ignore this and rely on DataPageIndex, DataPageSize, DataCount from the Grid.

Sometimes, the number of rows might be too large that the pagination area itself should be paginated. See the below as an example:

Example

In this example, there are 1,000 rows, 20 rows are shown per page, and the current active page index is 12.

Showing [241 to 260] from [1,000]

Below are the properties of the GridPagination according to the example.

Property Description
Count int
Number of Pages. In the above example, there are 1,000 rows and the page size is 20. So the Count is 50.
PageSize int
How many items (Buttons or Links) are shown per page (In the pagination area).
In the above example, the PageSize is 5.
Not to be confused with DataPageSize
PageStart int
The index of the first page in the current view..
In the above example, PageStart is 10
PageEnd int
The index of the last page in the current view.
In the above example, PageEnd is 14
PageIndex int
The active item (PageIndex).
In the above example, PageIndex is 12
HasPreviousPage bool
True when there are more items BEFORE the current page.
In the above example, HasPreviousPage is true
HasNextPage bool
True when there are more items AFTER the current page.
In the above example, HasNextPage is true
LastPageIndex int
The last PageIndex.
In the above example, LastPageIndex is 49
DataStart int
The row number (not index) of the first data item.
In the above example, DataStart is 241
DataEnd int
The row number (not index) of the last data item.
In the above example, DataEnd is 260

PaginationConfig

Property Description
PageSize int
How many items (Buttons or Links) are shown per page (In the pagination area).
Not to be confused with DataPageSize

ExportConfig

Property Description
Export bool
The Export Flag. When set to true, the data is prepared for export.
We're using the FileHelpers for exporting data to CSV
Delimiter string
The Delimiter that's used for seperating data in the exported CSV file/stream.

ColumnHidingException

When configuring the Grid using GridConfig, You can exclude (Hide) certain columns. But this is only possible if Select method is used on the data. Otherwise a ColumnHidingException is thrown

Safe

Select is used on this example. Hiding works as expected.

var shiftGrid =
await db
.Employees
.Select(x => new
{
    x.ID,
    x.FirstName,
    x.LastName,
})
.ToShiftGridAsync("ID", SortDirection.Ascending, new GridConfig
{
    Columns = new List<GridColumn>
    {
        new GridColumn
        {
            Field = "FirstName",
            Visible = false
        }
    }
});

Unsafe

Select is not used here and attempting to hide Firstname causes a ColumnHidingException to be thrown.

var shiftGrid =
await db
.Employees
.Select(x => new
{
    x.ID,
    x.FirstName,
    x.LastName,
})
.ToShiftGridAsync("ID", SortDirection.Ascending, new GridConfig
{
    Columns = new List<GridColumn>
    {
        new GridColumn
        {
            Field = "FirstName",
            Visible = false
        }
    }
});