Table of Contents
- Getting Started
- EO.Pdf
- EO.Web
- Overview
- Installation & Deployement
- EO.Web ToolTip
- EO.Web Rating
- EO.Web Slider & RangeSlider
- EO.Web ListBox
- EO.Web ComboBox
- EO.Web Captcha
- EO.Web ASPX To PDF
- EO.Web Slide
- EO.Web Flyout
- EO.Web EditableLabel
- EO.Web ImageZoom
- EO.Web Floater
- EO.Web Downloader
- EO.Web ColorPicker
- EO.Web HTML Editor
- EO.Web File Explorer
- EO.Web SpellChecker
- EO.Web Grid
- EO.Web MaskedEdit
- EO.Web Splitter
- EO.Web Menu
- EO.Web Slide Menu
- EO.Web TabStrip
- EO.Web TreeView
- EO.Web Calendar
- EO.Web Callback
- EO.Web MultiPage
- EO.Web Dialog
- EO.Web AJAXUploader
- EO.Web ProgressBar - Free!
- EO.Web ToolBar - Free!
- EO.WebBrowser
- EO.Wpf
- Common Topics
- Reference
Implementing Sorting |
Enable Sortting
To enable sortting, the following properties must be set correctly:
Property | Required | Remarks |
---|---|---|
GridColumn.AllowSort | Required | Sortting can be enabled on each individual column. Set a column's AllowSort to True to enable sorting on that column. |
ColumnHeaderAscImage | Optional | Optional image to be displayed on a column header to indicate items are sorted in ascending order. |
ColumnHeaderDescImage | Optional | Optional image to be displayed on a column header to indicate items are sorted in descending order. |
ColumnHeaderSortImageOffset | Optional | The sort image offset relative to the right edge of the column header. The default value is 20. You may need to adjust this value to fit your design. |
You can also set one of the grid column's SortOrder to either Ascending or Descending to indicate the grid can be sorted.
Handling Sorting Event
EO.Web Grid automatically handles sorting event in client mode. When the grid is in server mode or callback mode, you must handle ColumnSort event. Typically you would repoulate the grid with the new sort order. The following code demonstrates how to repopulate the grid inside ColumnSort event://Populate the grid private void LoadGridData(EO.Web.GridColumn sortColumn) { //Deciding sort orders string sortField = "PostedAt"; string sortOrder = "DESC"; if (sortColumn != null) { sortField = sortColumn.DataField; sortOrder = sortColumn.SortOrder == EO.Web.SortOrder.Ascending ? "ASC" : "DESC"; } string sortOrderReverse = sortOrder == "ASC" ? "DESC" : "ASC"; using (DemoDB db = new DemoDB()) { //Only fetch data for the current page from the database. //This is achieved by utilizing the "TOP n" clause supported //by Access/SQL Server database combined with sort orders. //Similar but different mechanism maybe needed with other //type of database engines. string sql1 = string.Format( "SELECT TOP {0} * FROM Topics ORDER BY {1} {2}", (Grid1.CurrentPage + 1) * Grid1.PageSize, sortField, sortOrder); string sql2 = string.Format( "SELECT TOP {0} * FROM ({1}) ORDER BY {2} {3}", Grid1.PageSize, sql1, sortField, sortOrderReverse); string sql3 = string.Format( "SELECT * FROM ({0}) ORDER BY {1} {2}", sql2, sortField, sortOrderReverse); OleDbDataReader reader = db.ExecuteReader(sql3); Grid1.DataSource = reader; Grid1.DataBind(); } } private void Grid1_ColumnSort(object sender, EO.Web.GridColumnEventArgs e) { LoadGridData(e.Column); }