Core - Support ListView sorting settings from the application model in Server Mode
Answers approved by DevExpress Support
We have implemented the functionality described in this ticket. It will be included in our next update(s).
Please check back and leave a comment to this response to let us know whether or not this solution addresses your concerns.
- v13.1.4Download Official Update
Currently, the XPObjectSpace class applies sorting for XPBaseCollection only, and ignores the XPServerCollectionSource:
public virtual void SetCollectionSorting(Object collection, IList<SortProperty> sortProperties) { if(collection is XPBaseCollection) { ((XPBaseCollection)collection).Sorting = GetSortingCollection(sortProperties); } }
This is because the the XPServerCollectionSource.DefaultSotring property uses a different format for sorting than the XPBaseCollection. It is however, possible to create a converter that will accept IList<SortProperty> and convert it into the required format. You can even do this yourself in your XPObjectSpace descendant by overriding the GetCollectionSorting/SetCollectionSorting methods.
If you wish to implement this feature yourself, here is sample code from our EF classes to help get you started:
public IList<SortProperty> GetSortProperties() { List<SortProperty> sortProperties = new List<SortProperty>(); String[] sortings = defaultSorting.Split(new String[] { ";" }, StringSplitOptions.RemoveEmptyEntries); foreach(String rawSorting in sortings) { String sorting = rawSorting.Trim(); String propertyName = ""; SortingDirection sortingDirection = SortingDirection.Ascending; if(sorting.ToLower().EndsWith(" desc")) { sortingDirection = SortingDirection.Descending; propertyName = sorting.Remove(sorting.Length - 5); } else { propertyName = sorting; } SortProperty sortProperty = null; if(propertyName.StartsWith("[")) { sortProperty = new SortProperty(propertyName, sortingDirection); } else { sortProperty = new SortProperty("[" + propertyName + "]", sortingDirection); } sortProperties.Add(sortProperty); } return sortProperties; } public void SetSortProperties(IList<SortProperty> sortProperties) { defaultSorting = ConvertSortPropertiesToString(sortProperties); entityServerModeFrontEnd.CatchUp(); } ... private String ConvertSortPropertiesToString(IList<SortProperty> sortProperties) { List<String> sortings = new List<String>(); if(sortProperties != null) { foreach(SortProperty sortProperty in sortProperties) { String sorting = sortProperty.PropertyName; if(sortProperty.Direction == SortingDirection.Descending) { sorting += " DESC"; } sortings.Add(sorting); } } return String.Join("; ", sortings.ToArray()); } ...