Hello,
I have implemented the custom sorting example http://www.telerik.com/help/wpf/gridview-sorting-custom.html
But using the following line of code results in an error that it cannot sort by System.Object
I am using this code on the server side so the code looks like this.
IQueryable<Customer> custList = dbProPlan.Customers.Where(cust => !cust.IsDeleted);
if (!string.IsNullOrEmpty(propertyName) && sortingState == SortingState.Ascending)
{
custList = custList.OrderBy(cust => cust.GetType().GetProperty(propertyName).GetValue(cust, null));
}
else if (!string.IsNullOrEmpty(propertyName) && sortingState == SortingState.Ascending)
{
custList = custList.OrderByDescending(cust => cust.GetType().GetProperty(propertyName).GetValue(cust, null));
}
numberOfItems = custList.Count();
double pages = numberOfItems / aPageSize;
int numberOfPages = (Math.Ceiling(pages) >= 1 ? (int)Math.Ceiling(pages) : 1);
aPageNumber = (numberOfPages < aPageNumber ? numberOfPages - 1 : aPageNumber);
IEnumerable<Customer> customerList = custList.Skip(aPageNumber * aPageSize).Take(aPageSize);
dbProPlan.Refresh(RefreshMode.OverwriteCurrentValues, customerList);
return customerList;
What do I need to change to get this working properly.
I have implemented the custom sorting example http://www.telerik.com/help/wpf/gridview-sorting-custom.html
But using the following line of code results in an error that it cannot sort by System.Object
employees = employees.OrderByDescending( employee => employee.GetType() .GetProperty( (e.Column as GridViewDataColumn).GetDataMemberName() ) .GetValue( employee, null ) );So I think the example code is not working, but I do not seem to be able to figure out how to get it working.
I am using this code on the server side so the code looks like this.
IQueryable<Customer> custList = dbProPlan.Customers.Where(cust => !cust.IsDeleted);
if (!string.IsNullOrEmpty(propertyName) && sortingState == SortingState.Ascending)
{
custList = custList.OrderBy(cust => cust.GetType().GetProperty(propertyName).GetValue(cust, null));
}
else if (!string.IsNullOrEmpty(propertyName) && sortingState == SortingState.Ascending)
{
custList = custList.OrderByDescending(cust => cust.GetType().GetProperty(propertyName).GetValue(cust, null));
}
numberOfItems = custList.Count();
double pages = numberOfItems / aPageSize;
int numberOfPages = (Math.Ceiling(pages) >= 1 ? (int)Math.Ceiling(pages) : 1);
aPageNumber = (numberOfPages < aPageNumber ? numberOfPages - 1 : aPageNumber);
IEnumerable<Customer> customerList = custList.Skip(aPageNumber * aPageSize).Take(aPageSize);
dbProPlan.Refresh(RefreshMode.OverwriteCurrentValues, customerList);
return customerList;
What do I need to change to get this working properly.