Minimize column width automagically

3 posts, 0 answers
  1. Neil Derraugh
    Neil Derraugh avatar
    1 posts
    Member since:
    Apr 2010

    Posted 02 Jun 2010 Link to this post

    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. Yavor
    Admin
    Yavor avatar
    11 posts

    Posted 08 Jun 2010 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jeremy
    Jeremy avatar
    96 posts
    Member since:
    Mar 2010

    Posted 03 Aug 2010 Link to this post

    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>
Back to Top