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

RadGrid with Horizontal Scrollbars

1 Answer 80 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Veenu
Top achievements
Rank 1
Veenu asked on 20 Jun 2012, 04:12 AM
How can I have a RadGrid with the following settings:
  1. Width = "100%"
  2. Autofit column width to content(Neither the column HeaderText nor the cell content should be truncated)
  3. Static Headers
  4. Horizontal Scroll bars
  5. Vertical Scroll bars

The number of columns in the grid are dynamic. I am able to get this effect only by specifying fixed width to the RadGrid and HeaderStyle.Width in pixels. But in this case the width of the column doesn't auto fit to the contents.


<telerik:RadGrid ID="rdgSample" runat="server"  Width="1200px">
     <MasterTableView  TableLayout="Fixed">
     </MasterTableView>
     <ClientSettings>
             <Scrolling AllowScroll="true" UseStaticHeaders="true" FrozenColumnsCount="2" />
     </ClientSettings>
     <HeaderStyle Width="250px" />
</telerik:RadGrid>

1 Answer, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 21 Jun 2012, 09:56 AM
Hello Veenu,

Note that when scrolling is enabled and UseStaticHeaders is True, the grid columns should declare HeaderStyle.Width. Otherwise an alignment issue could appear.
 
However, to achieve your goal you can try calling the client resizeToFit() method in order to resize the columns to their best fit. Refer to the code snippet below:
<script type="text/javascript">
    function pageLoad() {
        var grid = $find('<%=RadGrid1.ClientID %>');
        var columns = grid.get_masterTableView().get_columns();
        for (var i = 0; i < columns.length; i++) {
        columns[i].resizeToFit();
        }
    }
</script>

Regards,
Pavlina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Veenu
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Share this question
or