Changing The Report Rendering Settings Programmatically

5 posts, 0 answers
  1. Majar
    Majar avatar
    12 posts
    Member since:
    Nov 2018

    Posted 18 Mar Link to this post

    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,

    Majar

  2. Silviya
    Admin
    Silviya avatar
    335 posts

    Posted 21 Mar Link to this post

    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
  3. Majar
    Majar avatar
    12 posts
    Member since:
    Nov 2018

    Posted 21 Mar in reply to Silviya Link to this post

    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

     

  4. Silviya
    Admin
    Silviya avatar
    335 posts

    Posted 22 Mar Link to this post

    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
  5. Majar
    Majar avatar
    12 posts
    Member since:
    Nov 2018

    Posted 08 Apr in reply to Silviya Link to this post

    Hi Silviya,

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

    Regards,

    Majar

Back to Top