Ssrs - Keep a Table the Same Width When Hiding Columns Dynamically

SSRS - Keep a table the same width when hiding columns dynamically?

The only way I know how to accomplish this, is by altering your RDLC file during runtime. Basically, you can load up your RLDC file into memory (its just an XML file), locate the XML node that contains the width of your table - then modify the setting in memory. Once you have done that, you can refresh your reportViewer control using the RDLC file that is loaded in memory.

And yes, I have already done this, and it does work.

The following code example is to alter the data of an RDLC file in memory, via its XMLpath.

  Private Sub ModifyRDLCInMemory()

Dim xmlDoc As XmlDocument = New XmlDocument
Dim asm As Reflection.Assembly = Reflection.Assembly.GetExecutingAssembly()
'create in memory, a XML file from a embedded resource
Dim xmlStream As Stream = asm.GetManifestResourceStream(ReportViewer1.LocalReport.ReportEmbeddedResource)

Try
'Load the RDLC file into a XML doc
xmlDoc.Load(xmlStream)
Catch e As Exception
MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
End Try

'Create an XmlNamespaceManager to resolve the default namespace
Dim nsmgr As XmlNamespaceManager = New XmlNamespaceManager(xmlDoc.NameTable)
nsmgr.AddNamespace("nm", "http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition")
nsmgr.AddNamespace("rd", "http://schemas.microsoft.com/SQLServer/reporting/reportdesigner")

'Loop through each node in the XML file
Dim node As XmlNode
For Each node In xmlDoc.DocumentElement.SelectNodes(String.Format("//nm:{0}[@rd:LocID]", "Value"), nsmgr) 'XPath to LocID node.. You will want to change this to locate your Table Width node. You may need to read up on XMLPath
Dim nodeValue As String = node.InnerText 'Gets current value of Node
If (String.IsNullOrEmpty(nodeValue) Or Not nodeValue.StartsWith("=")) Then
Try
node.InnerText = YOURNEWVALUE

Catch ex As Exception
'handle error
End Try
End If
Next

ReportViewer1.LocalReport.ReportPath = String.Empty
ReportViewer1.LocalReport.ReportEmbeddedResource = Nothing
'Load the updated RDLC document into LocalReport object.
Dim rdlcOutputStream As StringReader = New StringReader(xmlDoc.DocumentElement.OuterXml)
Using rdlcOutputStream
ReportViewer1.LocalReport.LoadReportDefinition(rdlcOutputStream)
End Using

End Sub

SSRS - Shrink report width when hiding columns

The report body width - as with any column width and unlike heights - is a set value that cannot be changed on execution. You need to either put up with the white space, format your presentation layer to not be affected by the appearance of the white space or redesign your report so the objective of hiding the columns can be achieved in a different way.

Make hidden table column take no space in SSRS 2008 R2

I think you are looking at the Hidden property of the column. Something that is hidden will still take up space. What you want to change is the Visibility of the column. Right click on the column header and click Column Visibility and set it there.

SSRS tablix column CanGrow property for width?

I've been trying to do that myself (client side), without success. There is no property that would autosize the column width.

Check out this workaround: http://blog.sharepointalist.com/2009/05/ssrs-column-width-auto-size.html (I haven't tested it)

The best workaround I've found for client side reporting would be to set column's width in code or use multiple columns and show/hide them based on string length condition.

For example, column named AccNum2:

report.DetailSection1.ReportObjects.Item("AccNum2").width = 200

See this thread for details and other ideas:
http://social.msdn.microsoft.com/forums/en-US/sqlreportingservices/thread/9e6043f1-c458-4540-be59-d37b02feab8a/

Automatic re-size of a column based on a parameter in Microsoft reporting services

One trick to accomplish this is to create an extra column that is 8cm wide and contains the same data as the 5cm column.

You have columns A and B.

  • A is 5cm
  • B is 3cm
  • C contains the same data as A but is 8cm

Now select column A and set the column visibility (right-click the column header to edit this).
Set 'show or hide based on expression' to =IIF(Parameters!Paramter_p.Value = 1, True, False)

Do the same for B.

Do almost the same for C, but set the 'show or hide based on expression' to =IIF(Parameters!Paramter_p.Value = 1, False, True)

Now when Parameter_p = 1 Column A and B will be visible and take up 8cm. When Parameter_p <> 1 Column A and B will not be visible and will be replaced by the 8cm Column C.

This effectively looks like Column A expanded from 5cm to 8cm to take up the extra 3cm space from the hidden Column B.

Setting the minimum column width in SSRS

Update the ReportingServices.css file. By default, it's found in:

C:\Program Files\Microsoft SQL Server\MSSQL.3\Reporting Services\ReportManager\Styles\

Here's the CSS:

td, th
{
min-width:50px;
}

How to keep Reporting services table in the same page

You're using a horizontal table, a great tutorial is described here

You probably have most of the horizontal table figured out, just this part is important to your issue.

Step 4
Right-click on the column header and select "Edit Group". Enter this
for the group expression: =RowNumber(Nothing). This will cause the
matrix to give you one column per row of data. Since horizontal tables
can end up rather wide, you probably want your table wrap around to
the next "line" after a specific number of columns.

Just simply count the number of rows that fit your page exactly and define this number in your column group expression as described in the tutorial.

Dynamically resize if hiding rows conditional in SSRS report

Thanks to http://www.sqldev.org/sql-server-reporting-services/hidden-rows-still-displayed-9660.shtml
I found out I have to suppress / hide the rows in the static row group under the details group (switch to advanced mode first..).
When I did that the size of the Rectangle (container) was ignored when the rows where hidden :)
problem solved

Regards,

Mike



Related Topics



Leave a reply



Submit