Steps for getting started with the FlexGrid control in MVC applications:
This will create a FlexGrid with default behavior, which includes automatic column generation, column sorting and reordering, editing, and clipboard support.
The Getting Started example did not define any columns, so FlexGrid generated them automatically.
This example shows how you can define the columns using the FlexGrid's <c1-flex-grid-column></c1-flex-grid-column> tag.
Specifying the columns allows you to choose which columns to show, and in what order. This also gives you control over each column's Width, Heading, Formatting, Alignment, and other properties.
In this case, we use star sizing to set the width of the "Country" column. This tells the column to stretch to fill the available width of the grid so there is no empty space. On the "Amount" column, we set the format property to "n0", which results in numbers with thousand separators and no decimal digits. On the "Discount" column, we set the format property to "p0", which results in numbers with percentage and no decimal digits.
By default, FlexGrid allows you to select a range of cells with the mouse or keyboard, just like Excel. The selection-mode property allows you to change that so that you can select a Row, a Range of Rows, Non-Contiguous Rows (like in a List-Box), a Single Cell, a Range of Cells or disable selection altogether.
This example allows you to pick the selection-mode from a Wijmo ComboBox control.
FlexGrid has built-in support for fast, in-cell editing like you find in Excel. There is no need to add extra columns with Edit buttons that switch between display and edit modes.
Users can start editing by typing into any cell. This puts the cell in quick-edit mode. In this mode, pressing a cursor key finishes the editing and moves the selection to a different cell.
Another way to start editing is by pressing F2 or by clicking a cell twice. This puts the cell in full-edit mode. In this mode, pressing a cursor key moves the caret within the cell text. To finish editing and move to another cell, the user must press the Enter, Tab, or Escape key.
Data is automatically coerced to the proper type when editing finishes. If the user enters invalid data, the edit is cancelled and the original data remains in place.
You can disable editing at the Grid, Column, or Row levels using the is-read-only property of the Grid, Column, or Row objects. In this example, we make the ID and Country columns read-only.
FlexGrid supports grouping through the ICollectionView interface, which is identical to the one in .NET. To enable grouping, add one or more GroupDescription objects to the CollectionView.groupDescriptions property, and ensure that the grid's show-groups property is set to true (the default value).
GroupDescription objects are flexible, allowing you to group data based on value or on grouping functions. The example below groups dates by year; amounts by range returning three ranges: over 5,000, 1,000 to 5,000, 500 to 1,000, and under 500; and anything else by value. Use the menu to see the effects of each grouping.
Notice that the "Amount" column displays the totals in the group rows. We do this by setting the column's aggregate property to "C1.Web.Mvc.Grid.Aggregate.Sum". The aggregate is automatically updated when you edit the values in the column.
The FlexGrid supports filtering through the <c1-flex-grid-filter></c1-flex-grid-filter> tag. To enable filtering, add the <c1-flex-grid-filter default-filter-type="C1.Web.Mvc.FilterType.Both"></c1-flex-grid-filter> tag within <c1-flex-grid></c1-flex-grid> tag.
In this example, we create a filter for the ID, Country, Product, Color, Start and get the filter value from the input control.
The FlexGrid supports paging through the <c1-pager owner="pFlexGrid"></c1-pager> tag. To enable paging, set the page-size atrribute of <c1-items-source> to the number of items you want on each page, and use Pager control to bind this FlexGrid.
In this example, we set PageSize to show 10 items per page. We add Pager control and set owner attribute to the FlexGrid id, then we can switch pages.
FlexGrid has an item-formatter property that gives you complete control over the contents of the cells.
This example uses a JavaScript function to create value ranges that return named colors. We then call this function in the FlexGrid's item-formatter and pass the cell's data in order to conditionally set the cell's foreground color.
The appearance of the FlexGrid is defined in CSS. In addition to the default theme, we include about a dozen professionally designed themes that customize the appearance of all Wijmo controls to achieve a consistent, attractive look.
You can customize the appearance of the grid using CSS. To do this, copy CSS rules from the default theme to a new CSS file and modify the style attributes you want to change.
In this example, we add a "custom-flex-grid" class to the grid element by using class property and define some CSS rules to create a simple "black and white, no borders" theme for any grids that have the "custom-flex-grid" class.
In addition to grouping, FlexGrid supports hierarchical data, that is, data with items that have lists of subitems. This type of hierarchical structure is very common, and is usually displayed in a tree-view control.
To use FlexGrid with hierarchical data sources, set the child-items-path property to the name of the data element that contains the child elements. The grid automatically scans the data and builds the tree for you.
By default, FlexGrid allows you to enter empty values in columns of type string, and will not allow empty/null values in columns of any other type.
You can change this behavior using the is-required property on grid columns. If you set the is-required property to false, the grid will allow you to enter empty values in that column, regardless of type. Conversely, if you set the is-required property to true, the grid will not allow empty values even in string columns.
Setting is-required to null reverts to the default behavior (nulls allowed only in string columns).
The grid below reverts the default behavior. It sets is-required to false for the first column, and to true for all others. You can delete content that is not required by entering an empty string or simply by pressing the delete key.