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

Minimize column width automagically

2 Answers 99 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Neil Derraugh
Top achievements
Rank 1
Neil Derraugh asked on 02 Jun 2010, 05:35 PM
Is there an easy way to minimize column width?  For example for Edit and Delete columns the minimum column width would always be the same based on the style characteristics and the text for the two columns.  For those familiar with Android development I'm looking for something similar to android:width="wrap_content" for a View.  I don't want to specify an exact width like 50px I want to set it to "minimum" or something.

2 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 08 Jun 2010, 07:21 AM
Hi Neil,

Presently, there is no similar straightforward setting to employ.
You can set the values to these columns to some minimal width, which is just enough to accommodate their contents, since they are known in advance, which is not the case with the other columns.
Another alternative is to set the width of the columns at runtime, either in the ColumnCreated server side handler, or in the PreRender event handler.
I hope this information helps.

Greetings,
Yavor
the Telerik team

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 Public Issue Tracking system and vote to affect the priority of the items.
0
Jeremy
Top achievements
Rank 1
answered on 04 Aug 2010, 03:24 AM
I got around this problem by sticking the radgrid in a div with width = 400px and overflow set to visible, with a bit of javascript to change the size after loading. Not suitable for all occasions I'm sure, but works for me :)

<div style="width:400px; overflow: visible">
 
    <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false"
            AllowPaging="True" Skin="Vista">
        <MasterTableView>
            <PagerStyle AlwaysVisible="True" />
        </MasterTableView>
        <ClientSettings>
            <ClientEvents OnGridCreated="GridCreated" />
        </ClientSettings>
    </telerik:RadGrid
                                  
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script type="text/javascript">
            function GridCreated(sender, args) {
                var dataWidth = sender.get_masterTableView().get_element().clientWidth;
                if (dataWidth > 400) {
                    sender.get_element().style.width = dataWidth + "px";
                }
            }
        </script>
    </telerik:RadCodeBlock>
 
</div>
Tags
Grid
Asked by
Neil Derraugh
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Jeremy
Top achievements
Rank 1
Share this question
or