[CLOSED] Auto resize the width of the column in grid as per data in column

  1. #1

    [CLOSED] Auto resize the width of the column in grid as per data in column

    Hi,

    How can we set the auto width to a column of grid as per the data in the column? I mean, as per the data in the column, the column width should be auto resize in Ext.Net.

    Thanks in advance.
    Last edited by fabricio.murta; May 17, 2019 at 8:32 PM. Reason: no feedback from the user in 7+ days
  2. #2
    Hello @iansriley!

    Thanks for taking the time to create the new thread, I hope you understand!

    To make the column fit its contents, you can use the autoSize() column method. It is not a config option, because it needs to be run when the grid is actually drawn. So you should call it for each column you want to fit when the grid is drawn, tying the code execution to some page event.

    I have found this event handler code in Sencha website and tested it on a simple grid, and it worked for me in Ext.NET 4.8, so it should be worth a try: Post #3 in 'Auto fit column widths instead of having fix widths' Sencha thread

    The catch is in the custom autoSizeColumn: true in the column definition, and the grid view's refresh listener.

    You can specify this custom config in WebForms/ASPX as AutoSizeColumn="true" without long CustomConfig blocks. Even though it is not implemented server-side, Ext.NET passes thru what it does not support, and this will be output just how it needs to.

    The refresh listener can be set just like this:

    var handleViewRefresh = function(dataview) {
        Ext.each(dataview.panel.columns, function(column) {
            if (column.autoSizeColumn === true) {
                column.autoSize();
            }
        })
    }
    And used in ASPX with this block in the grid panel definition:

    <ViewConfig runat="server">
        <Listeners>
            <Refresh Fn="handleViewRefresh" />
        </Listeners>
    </ViewConfig>
    Beware if you have a grid with lots of records, and buffered rendering is enabled (it is by default). If some records are not rendered at the time the autoSize() method runs, and a larger content cell lies in the non-rendered rows, width for the column, unless you keep firing the width code -- which will then make the grid "jump" into new column widths as the user scrolls. Explicitly disabling buffered render should ensure the width is set up right and provide a decent user experience.

    Hope this helps!
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Hello, @iansriley!

    As per your other post here, it looks like this one is good to be closed, right? Or is the auto resize still not working the way you need, keeping in mind the conflicts with flex are being dealt with in the thread of the thread of the post liked above?

    We may mark this thread as closed given you don't post a follow up in 7+ days from now, but we won't lock up the thread, so you'd still be able to post a follow-up at your discretion.

    Looking forward to your feedback!
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. Replies: 3
    Last Post: Dec 19, 2014, 9:52 AM
  2. Replies: 16
    Last Post: Jun 05, 2014, 10:19 AM
  3. [CLOSED] Gridpanel command column auto width
    By Daly_AF in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Apr 11, 2013, 12:29 PM
  4. [CLOSED] Grid Panel : Column width (Auto width)
    By legaldiscovery in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Sep 24, 2011, 8:31 PM
  5. Column Layout auto width problem in IE
    By sz_146 in forum 1.x Help
    Replies: 0
    Last Post: Jan 05, 2009, 10:59 AM

Tags for this Thread

Posting Permissions