This is a migrated thread and some comments may be shown as answers.

Changing The Report Rendering Settings Programmatically

4 Answers 363 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Majar
Top achievements
Rank 1
Majar asked on 18 Mar 2019, 12:32 PM

Hi,

 

We have a requirement to set the NoHeader parameter value to true in some reports and false in others. Is there a way to do it from the code behind of the report? I have found a way for window forms application (https://www.telerik.com/forums/programmatically-set-noheader). But our requirement is for web application

 

Regards,

4 Answers, 1 is accepted

Sort by
0
Silviya
Telerik team
answered on 21 Mar 2019, 08:57 AM
Hi Majar,

For a web application scenario, you can set CSV settings to the reports controller like:
public override HttpResponseMessage CreateDocument(string clientID, string instanceID, CreateDocumentArgs args)
{
    if (args.Format == "CSV")
    {
        args.DeviceInfo.Add("NoHeader", true);
    }
 
    return base.CreateDocument(clientID, instanceID, args);
}

Add your own logic which reports should inherit the NoHeader setting.

Best Regards,
Silviya
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Majar
Top achievements
Rank 1
answered on 21 Mar 2019, 09:59 AM

Hi Silviya,

Thanks.

But is there a way to get report name in CreateDocument action?The NoHeader parameter should be set only for few reports, not all. For that the report name should be available in the action.

 

Regards,

Majar

 

0
Silviya
Telerik team
answered on 22 Mar 2019, 08:20 AM
Hi Majar,

You would have to check for the instance of the required report overriding the CreateInstance method. For example, I simply search for reports starting with "R" letter and add it's instance ID into a dictionary. Then make another check in CreateDocument method for the instance and apply the needed changes, e.g. set NoHeaders setting:
public override HttpResponseMessage CreateInstance(string clientID, ClientReportSource reportSource)
{
    var instance = base.CreateInstance(clientID, reportSource);
    var rs = reportSource.Report;
    var firstCommaIdx = rs.IndexOf(',');
    var firstIdx = rs.LastIndexOf('.', firstCommaIdx);
    var actualReportName = rs.Substring(firstIdx+1, firstCommaIdx - firstIdx - 1);
 
    if (actualReportName.StartsWith("R"))
    {
        var instanceResponse = instance.Content.ReadAsStringAsync().Result;
        var instanceId = instanceResponse.Split(new[] { ':' }).Last().Trim(new[] { '{', '\"', '}' });
        noHeaderReports.TryAdd(instanceId, instanceId);
    }
    return instance;
}
 
public override HttpResponseMessage CreateDocument(string clientID, string instanceID, CreateDocumentArgs args)
{
    if (args.Format == "CSV"
    {
        if (noHeaderReports.Keys.Contains(instanceID))
        {
            args.DeviceInfo.Add("NoHeader", true);
        }
    }
 
    return base.CreateDocument(clientID, instanceID, args);
}

Please note that this is just for testing purpose and I stripped a full assembly qualified the name of TypeReportSource to get the actual report name. You need to create your own logic for handling the required report instances.

Best Regards,
Silviya
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Majar
Top achievements
Rank 1
answered on 08 Apr 2019, 10:32 AM

Hi Silviya,

Thanks, I could get the report name in the CreateDocument action by calling the GetReportInstanceKey method of the ReportsControllerBase Class.

Regards,

Majar

Tags
General Discussions
Asked by
Majar
Top achievements
Rank 1
Answers by
Silviya
Telerik team
Majar
Top achievements
Rank 1
Share this question
or