We've been using Telerik Reports for years, and have allowed users to set up their own sorting. The below code worked no problem, until we recently upgraded all the way from version Q3 2015 to R1 2023. Now, sorting is never obeyed, despite the parameter on the report getting set - we write out the criteria one the outputted report, and that is correct. We've traced this code through with no errors, and the sortings do seem to be applied to the report object, but they are ignored when the report is built.
Any ideas to point us in the right direction? It's very frustrating to have bought a new version, but have features that worked before now fail without warning...
protected override void OnNeedDataSource(object sender, EventArgs e)
{
base.OnNeedDataSource(sender, e);
var report = sender as Telerik.Reporting.Processing.Report;
//// Report Post Formatting.
// Apply Sorts.
if (report.Parameters["Sortings"].Value != null)
{
Common.ApplySort(this, report.Parameters["Sortings"].Value.ToString());
}
}
public static void ApplySort(Report report, string sortingColumns)
{
// sorting Columns string format: ColumnName:Asc;ColumnName:Desc
if (sortingColumns == null)
return;
foreach (var item in sortingColumns.Split(','))
{
// Get The field value for the column to sort by... IE. SellthroughValuePercent is an iff calculation.
report.Report.Sortings.Add(new Sorting
{
Expression = string.Format("=Fields.[{0}]", item.Split(':')[0]),
Direction = item.Split(':')[1] == "Asc" ? SortDirection.Asc : SortDirection.Desc,
});
}
}