Resize the width of a report table by using a parameter

Mario Formosa 41 Reputation points
2021-01-29T17:43:48.847+00:00

Good evening
I have a report that uses a table to display a list of orders. This report includes a Boolean parameter used to hide/show two columns in that table. When true, the two columns are displayed. When columns are displayed, the table occupies the entire width of the page, but when they are not displayed, a lower-width table is obviously displayed that leaves a blank space to its right.

I would like the table to occupy with its width all the space available on the page even when the two columns mentioned above were hidden.

I understood that for the Width property of a column in the table, you cannot insert an expression; otherwise I could have increased or decreased the Width, for example of the column that contains the customer's name, depending on the value of the parameter, so that the table was always the same width.

How do you think I could solve this problem?

Thank you.

SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
2,818 questions
{count} votes

Accepted answer
  1. Joyzhao-MSFT 15,566 Reputation points
    2021-02-01T04:30:44.203+00:00

    Hi @Mario Formosa
    When you hide/show the report through parameters, the column width is usually fixed, and the column width cannot be set by expression. But I have a way that works well to resolve your issue. You could set the dynamic column width by inserting a chart in the row.

    The following is my test:

    1. I have the following table. I set the column visibility to hide the Sales column when Rank<=3, and display the Sales column when Rank>3.
      62289-01.jpg
      62354-02.jpg
      62290-03.jpg
    2. Insert a row at the bottom of the table, insert a chart in each column, refer to the figure above. Then change the DynamicWidth of the Rank column and Employee ID column to an expression similar to the following =iif(Fields!Rank.Value<=3, "12cm", "6cm"), and change its DynamicHeight to "0cm", You can set the value of DynamicWidth according to your needs.
      62355-06.jpg
      62338-07.jpg
    3. Set the hidden Sales column, change DynamicWidth to the expression of =IIF(Fields!Rank.Value<=3,"0cm","6cm"), and change its DynamicHeight to "0cm", where "6cm" "It can be replaced according to your needs.
    4. Preview the report
      62356-04.jpg
      62361-05.jpg
      We can see that the column width has changed according to the hide/show of the column.
      Hope this helps.
      Best Regards,
      Joy

    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Williams, Jeffrey A 481 Reputation points
    2021-01-29T17:58:27.867+00:00

    The only option I can think of is to have 2 separate tablix - and make one or the other visible based on your parameter.

    1 person found this answer helpful.
    0 comments No comments

  2. Mario Formosa 41 Reputation points
    2021-02-08T16:41:48.817+00:00

    Good evening
    thank you for your answers and excuse me if I answer only now.
    The solutions you have proposed seem to me to be valid, but I have seen that from the report properties window from the code sheet you can refer to the elements of the report.
    For example, the following line of code is accepted without running the report returning errors:
    dim ri As Microsoft.ReportingServices.ReportProcessing.ReportObjectModel.ReportItems
    Analyzing the report XML, the Tablix element is included in the ReportItems element, so I thought I'd get a reference to the Tablix in my code to set its Width property.
    The trouble is that despite reading the MSDN documentation, I could not in any way get a reference to the Tablix in the code.
    I also saw that there would be the possibility of extending a Tablix control to equip it, for example, with natively unforeseen features, and because of the problem I put in this thread, for example, it could be extended in such a way that, through a Boolean property that you could call WidthAsBodyWidth, when corroborated to True, the Tablix would fill all the width of the Body always , even when the sum of the column widths was less than that of the Body.
    What do you think?
    Thank you.

    0 comments No comments