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.
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.
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 customautoSizeColumn: true
in the column definition, and the grid view's refresh listener.
You can specify this custom config in WebForms/ASPX asAutoSizeColumn="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:
And used in ASPX with this block in the grid panel definition:Code:var handleViewRefresh = function(dataview) {
Ext.each(dataview.panel.columns, function(column) {
if (column.autoSizeColumn === true) {
column.autoSize();
}
})
}
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.Code:<ViewConfig runat="server">
<Listeners>
<Refresh Fn="handleViewRefresh" />
</Listeners>
</ViewConfig>
Hope this helps!
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!