Title: Dynamic Table/Column Width Resizing - How To? Post by: Jay27 on November 03, 2018, 10:24:06 AM Good day,
I'd like my table to resize according to the browser's viewport width. The default behavior is that the table takes on whichever width is available on load time, but then never resizes again. I've tried setting fit="true". This makes the table dynamically resize, but it also makes it not display any records. Only the header & toolbar are shown. The api call to fetch json data is successfully made, but the records aren't loaded into the datagrid. There's nothing to be shown because the grid's html does not contain the records. Also, I am trying to get fitColumns to work. From other forum threads, I have learned that you've got to set the width on columns in order for fitColumns to work. I don't understand why, because the whole idea of fitColumns is that it fits the columns automatically. Anyway, I'm experimenting with it. When I show only 3 columns that have width:1 (because width:0 doesn't work well), the datagrid does a decent job of making them occupy (almost) the whole available width of the browser viewport. When I do this with more columns, at some point the entire fitColumns functionality just stops working. The columns only take up less than half of the viewport and they aren't even wide enough to display the data they contain. When I set width:100 on all the columns, they are spread out across the viewport pretty well, with a little bit of space to spare on the right side. When I stretch the browser and reload, again the columns take up the whole space. But because I've set the width, the columns aren't really autofitting at all. The column with IDs is far too wide. The column with lengthy email addresses isn't showing all of its data without being manually widened. When dynamically resizing, columns should take on widths that is proportional to the length of the data they contain. Not setting any width so far works the best. But, according to the documentation, not setting a width will cause worse performance. And I can notice this when rejecting/accepting 1 record change in only 6 records. So why do I have to set width to get fitColumns to do anything? And can I set the width to be min/max/auto? What's the best strategy here for getting the datagrid and the columns to resize dynamically and correctly when the user changes the browser viewport? My code: Code: <table id="dgAccounts" class="easyui-datagrid" title="Accounts" Title: Re: Dynamic Table/Column Width Resizing - How To? Post by: jarry on November 04, 2018, 05:48:04 AM Please look at this example http://code.reloado.com/uheren/edit#preview
Set the 'fixed' to true for the 'id' column to prevent it from becoming too wide. When the datagrid component is resized, set the 'fitColumns' to true or false according the width of the datagrid. You can also set the column priority, please refer to https://www.jeasyui.com/forum/index.php?topic=6653.0 Title: Re: Dynamic Table/Column Width Resizing - How To? Post by: Jay27 on November 04, 2018, 11:10:05 AM You've pasted a preview link which, unsurprisingly, isn't showing your example.
Quote When the datagrid component is resized, set the 'fitColumns' to true or false according the width of the datagrid. The grid resizing isn't working. Aside from that, I don't understand this sentence. Can you clarify? |