I am trying to create a custom DataGrid with built in support for sorting when combined with an EntityCollection as the DataSource.
My question is: Is it possible to sort a collection on a field if all you have is a field name?
Creating a SortExpression, from what I have been able to find, requires that you an pass <EntityName>FieldIndex. The problem is, the DataGrid doesn't know what concrete implementation of EntityBase is being used and there is no generic SortClauseFactory.Create(int fieldIndex,....) function. For example, the following line wouldn't work.
PrepareCollection(EntityCollectionBase collection, string fieldName)
{
SortClause sorter = SortClauseFactory.Create(collection[0].Fields[fieldName].FieldIndex, (sortASC ) ? SortOperator.Descending : SortOperator.Ascending);
}
That is as simple as I can try to explain it. I hope someone will be able to help me.