Steps for getting started with the FlexGrid control in MVC applications are as follows:
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 Columns property.
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 SelectionMode 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 SelectionMode from a C1 ASP.NET MVC's 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.
There are two modes for updating the data to the server.
Notices: If the user wants to commit the update operation to the datasource server, the Update, Delete or Create action url should be provided. And the corresponding codes used to update the datasource should be written in the corresponding action.
Notices: In this mode, the BatchEdit action url should be provided and the corresponding codes used to update the datasource should be written.
You can disable editing at the Grid, Column, or Row levels using the IsReadOnly property of the Grid, Column, or Row objects. In this example, we make the ID column read-only.
FlexGrid supports grouping of client side data, set the GroupBy property to a column name for grouping the data according to a column.
Internally, FlexGrid supports grouping through the client side IItemsSource interface. To enable grouping at client side, add one or more GroupDescription objects to the itemsSource.groupDescriptions property. It is easy to let the grid grouped by some field by calling the method GroupBy of FlexGridBuilder with the corresponding field name. And ensure that the grid's ShowGroups 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 "Sum." The aggregate is automatically updated when you edit the values in the column.