I have a page with multiple webdatagrids on it, I use the javascript column resizing solution I found on this site that works fine. Due to that I don't use any width sizing for my grids. On a page with three grids in an update panel (these grids are part of a custom control I made that will display a specific grid based on setup) I have the following types: a paged grid with multiple columns, a grid with 2 columns and a grid with 1 column. When there is a partial postback (in this case by selecting another page in the paged grid, but have also tested with timer control) the multi column grid expands to 100%, but the paged grid is fine. I check the HTML and there the inline style now shows Width=100%. The only way I can make that grid not expand is to hide a column so it's a single column. What is the cause of the inline style being changed on postback and how can I stop it?
Inline style after first load: style="height: 518px; overflow: hidden; width: 235px; visibility: inherit;
Inline style after postback: style="height: 518px; overflow: hidden; width: 100%; visibility: inherit;
Hello HansenC,
Thank you for posting in our community!
I would like to ask you for a sample that demonstrate this issue. Send us as attachment small working isolated sample where we can observe the described issue, so we can continue with our investigation.
Here is a simple example of this issue. After more testing I believe it has something to do with the column resizing that is called since if I remove the resizing it does not happen, but then the header text gets cut off without it. I have tried using the initialize client event property of the grid as well with the same results. The paging in the grid is not actually working for some reason but you can see on any postback the grid gets an inline style of width: 100%.
The issue I'm actually having is the header text gets cut off unless I specify a width because they are longer than the data cell contents. The only solution I've found for this was through a post on this site by another one of your team members to use the method in my sample. I changed my code to use the client event to call the JS function with the same result (updated my files to show this). Is there a CSS solution so the columns will expand to the header text length without defining a width?
Hello,
Thank you for the provided code snippet and explanation!
I have checked the sample and it seems that on Timer tick the resizeDashboardGrid function is not executed as expected. This is because of the last check "resize based on header text length" I have changed the logic and now everything is working fine. You can have a look at the attached sample.
// resize based on header text lengthif (col.get_headerElement().offsetWidth != col.get_headerText().length * 8) { var newWidth = (col.get_headerText().length * 8).toString() + 'px'; col.set_width(newWidth);}
Let me know if I may be of further assistance.
Having a closer look, this did not fix the issue in the way that I thought it did. While the grid size no longer goes to 100% width, the cell contents will now get cut off if they are shorter than the header length. You can see this in the sample I sent you by changing the column header text from 'station' to 'city'. My goal is to have the column width the minimum size to show the data or the headers, whichever is longer, on a single line.
Edit: I also wanted to add, with the original javascript, everything works fine the first load. Except on postback something changes and adds in a 'width=100%' inline style to the control. I've compared before and after postbacks in the HTML/CSS and that's the only change I can see in the grid is that CSS attribute changed, but it's inline not from any CSS file. I even put an alert in the javascript before it does any resizing and on the postback the grid is already 100% width by the time it reaches the javascript.
Hi HansenC,
The layout feature that you want is too custom. We cannot provide native functionality of the grid that can achieve that. This is caused by the fact that most of the CSS solutions are applied to normal tables. In our case the grid contains table for each of the sections: header, body, footer. Then the auto-resizing that relies on browser native calculation cannot be applied. The other option is to use JS as you have proposed, but then you have to manually handle all the possible cases:
Thank you for your assistance that gave me what I needed to get it working. I ended up using hidden fields to track the size after first load and set the width in code behind on postback, then the column resizing worked given it had a restricted width to work with.
I'm glad to see you resolved your issue.
Thank you for sharing it with us and our community!