Is it possible to control the sorting direction of the table via report parameter?
I want to pass Asc or Desc value as Report Parameter and sort the table rows.
Please advice.
Thanks
BV
Neli
Telerik team
commented on 08 Dec 2021, 04:07 PM
Hi Balaji,
I am afraid that we don't provide such a functionality out-of-the-box. However, because I see that you use the HtmlReportViewer, you may test implementing CustomReportSourceResolver a which will allow you to set the Sorting programmatically. In it, you need to make an instance of the report, access the table and add the Sorting:
publicclassCustomReportSourceResolver : IReportSourceResolver
{
public ReportSource Resolve(string report, OperationOrigin operationOrigin, IDictionary<string, object> currentParameterValues)
{
var reportPackager = new ReportPackager();
InstanceReportSource irs = new InstanceReportSource();
using (var sourceStream = System.IO.File.OpenRead("Reports/Report1.trdp"))
{
var reportInstance = (Report)reportPackager.UnpackageDocument(sourceStream);
var table1 = (Table)reportInstance.Items.Find("table1", true).FirstOrDefault();
table1..Sortings.Clear();
table1..Sortings.Add(new Telerik.Reporting.Sorting("= Fields.Group", Telerik.Reporting.SortDirection.Asc));
irs.ReportDocument = reportInstance;
}
return irs;
}
}
Hi Balaji,
I am afraid that we don't provide such a functionality out-of-the-box. However, because I see that you use the HtmlReportViewer, you may test implementing CustomReportSourceResolver a which will allow you to set the Sorting programmatically. In it, you need to make an instance of the report, access the table and add the Sorting:
public class CustomReportSourceResolver : IReportSourceResolver { public ReportSource Resolve(string report, OperationOrigin operationOrigin, IDictionary<string, object> currentParameterValues) { var reportPackager = new ReportPackager(); InstanceReportSource irs = new InstanceReportSource(); using (var sourceStream = System.IO.File.OpenRead("Reports/Report1.trdp")) { var reportInstance = (Report)reportPackager.UnpackageDocument(sourceStream); var table1 = (Table)reportInstance.Items.Find("table1", true).FirstOrDefault(); table1..Sortings.Clear(); table1..Sortings.Add(new Telerik.Reporting.Sorting("= Fields.Group", Telerik.Reporting.SortDirection.Asc)); irs.ReportDocument = reportInstance; } return irs; } }