What I need is an event when I click on a header.
I was just evaluating and testing the Teleriks gridview and they have an event called SortCommand.
I'm needing just about the same as this:
C# protected void RadGrid1_SortCommand(object source, GridSortCommandEventArgs e)
{
if ("Name".Equals(e.CommandArgument))
{
e.Canceled = true;
GridSortExpression expression = new GridSortExpression();
expression.FieldName = "Name";
switch (e.OldSortOrder)
{
case GridSortOrder.None:
case GridSortOrder.Descending:
expression.SortOrder = GridSortOrder.Ascending;
e.Item.OwnerTableView.DataSource = GetData("Name", true, skip, take);
//Response.Write("asc");
break;
case GridSortOrder.Ascending:
expression.SortOrder = GridSortOrder.Descending;
e.Item.OwnerTableView.DataSource = GetData("Name", false, skip, take);
//Response.Write("desc");
break;
}
RadGrid1.CurrentPageIndex = 0;
e.Item.OwnerTableView.SortExpressions.AddSortExpression(expression);
e.Item.OwnerTableView.Rebind();
}
}
...
private IList<Swh.Wb8.Entities.Category> GetData(string sortColumn, bool sortOrder, int skip, int take)
{
IGenericDao<Swh.Wb8.Entities.Category> Dao = new GenericDao<Swh.Wb8.Entities.Category>();
IList<Swh.Wb8.Entities.Category> list = Dao.GetObjects(new Order(sortColumn, sortOrder), skip, take, out recordCount);
RadGrid1.VirtualItemCount = recordCount;
return list;
}
What happens is:
When I click a header I'll get the clicked column name and order(asc/desc) and sends the values to the database (GetData)
GetData returns the new rows and binds it to the grid.
Telerik also have the superb feature of what they call: VirtualItemCount.
As you see from my IList<T> from NHibernate I have an output parameter (recordcount) with the total rows in database.
I send in the recordcount into the grid so it can caluculate the paging mechanism. Fantastic! :)
If you can fix this you will be my hero! :)
Best Regards
Mattias