logo

Working with GridState (a table display settings class)

GridState is a class that contains table display settings in ELMA Web Application. Main properties of this class:

Name

Type

Description

PageSize

int

Number of entries per page

CurrentPage

int

Current page of the table

SortExpression

string

Expression for sorting

SortDirection

ListSortDirection

Sorting direction (acsending, descending)

ColumnStates

GridStateSet

List of columns + the visibility. Each column is described by the ColumnState class

AvailableColumns

List<SelectListItem>

Columns available for display

SelectedColumns

 

List<SelectListItem>

Columns selected for display

Creating a table state in scripts

To work with the class, add the namespace:

using EleWise.ELMA.Web.Mvc.Models.Grids

To create a state from scratch, use a special static method of the GridState class. The table unique name and type that will be displayed in the table are passed as parameters. The method will return a ready table state.

var gridState = GridState.CreateNew(string.Format("Folder_{0}", model.Entity.Uid), typeof(IDmsObject));

If you want to change the list of columns, do the following: go through ColumnStates and set the Hidden property in the required column to the respective value (if true, the column is hidden, if false, the column is displayed). To change the order of displayed columns, you need to correctly set the Order property of the ColumnState class. Columns are sorted by this property in ascending order.

To set the default sorting use the SortExpression and SortDirection properties.

gridState.SortExpression = "Name";
gridState.SortDirection = ListSortDirection.Descending;