How to achieve auto width Column in sap.ui.table.Table? - sapui5

I am using sap.ui.table.Table. This table has some very good feature but I am having a tough time to figure out how to set the column to auto width.
Currently, all the columns are fixed size but I want something if column A value is small, then auto adjust it rather than having fixed size. Same for if the column value is large, then adjust it to show the value.
I saw the other question sap.ui.table.Table how to optimize column widths but the answers there are to get column layout with fixed sizes, not auto width.

The control sap.ui.table.Column offers a property called autoResizable by which the user can resize the column width depending on the content of the column's template.
<Column
autoResizable="true"
...
From API Reference:
Enables auto-resizing of the column on double clicking the resize bar. The width is determined on the widest currently displayed content. It does not consider rows which are currently not scrolled into view.
However, as you can see, it requires user interaction. Doing it without user interaction programmatically can be achieved by using the (currently experimental) API autoResizeColumn from sap.ui.table.Table.
myTable.autoResizeColumn(/*ColumnIndex*/); // experimental!
Here is an example of both approaches: https://embed.plnkr.co/NQpkJo/.

Related

How to adjust the width of the ag-grid container based on its contents?

In ag-grid, the value of domLayout can be set to autoHeight in order to disable vertical scrolling of the ag-grid panel. Instead, the entire page adapts its height to show all the rows.
How can I have the same behavior for the horizontal scrolling?
There is the suppressHorizontalScroll option when set to true hides the horizontal scroll bar, but this doesn't force the entire page to have a scroll. Instead, the overflowing content is just hidden.
you can do this to some extent by juggling the minWidth, maxWidth, and width attributes on your columns while setting the width of the columns automatically based on their content using the gridColumnApi.autoSizeColumns(colId) method.
I say to some extent because it is quite hard, with agGrid, to set different row sizes for rows with certain cells having a lot of text or big images in them. This would force some columns to expand to accommodate for the content, or just clip it completely. Thus forcing the horizontal scroll.
Note : for the method above to work, you need to call gridColumnApi.autoSizeColumns(colId) after you get your rows setUp.

Make intrinsicContentSize adapt to external constraints

The Context
I often have situations where I want multiple NSTextViews in a single NSStackView. Naturally, Auto Layout is not pleased with this since this makes height ambiguous (assuming the stack view is not set to fill equally). Even after adding constraints to resolve these issues, macOS Interface Builder appears to have a bug where it refuses to actually update frames when asked.
For this reason and others, I'm attempting to create a TextBox class (subclassing NSView) to encapsulate an NSTextView (and associated scroll view) and include an intrinsic content size to avoid layout issues. The intrinsic content size would be calculated based on a user-specified min and max number of lines (to display without requiring scroll). In other words, up to a certain max number of lines, TextBox will resize itself so that scrolling is unnecessary.
The Problem
This would seem to require an intrinsicContentSize that is dependant on frame width.
But, intrinsicContentSize documentation states:
The intrinsic size you supply must be independent of the content frame, because there’s no way to dynamically communicate a changed width to the layout system based on a changed height.
However, Auto Layout Guide states:
A text view’s intrinsic content size varies depending on the content, on whether or not it has scrolling enabled, and on the other constraints applied to the view. For example, with scrolling enabled, the view does not have an intrinsic content size. With scrolling disabled, by default the view’s intrinsic content size is calculated based on the size of the text without any line wrapping. For example, if there are no returns in the text, it calculates the height and width needed to layout the content as a single line of text. If you add constraints to specify the view’s width, the intrinsic content size defines the height required to display the text given its width.
Given that when scrolling is disabled in a text view:
If you add constraints to specify the view’s width, the intrinsic content size defines the height required to display the text given its width.
Then it seems there is a way to do what I want by perhaps looking at existing constraints.
The Question
How can I define an intrinsic content size that calculates height based on otherwise specified width, as described in the last quoted sentence above?
The solution should produce the effect described in "The Context" and not produce errors or warnings when used inside a Stack View.

How to fit with column to content

I need to fit the column width to the content of the column and allow scrolling horizontally.
I am using ag-grid with JavaScript
exist a way to do this? I always fund example using gridOptions.api.sizeColumnsToFit() but this will fit to the grid.
any help link?
Use columnApi.autoSizeColumns() not api.sizeColumnsToFit()

GTK+ 3: Restore TreeViewColumn widths without making them behave as if manually sized

I have a TreeView whose columns are all expandable with fixed-mode sizing. I would like to restore the widths of the columns when the user restarts the app. It seems that calling set_fixed_size is the way to do this, but:
If I set only the widths of the columns that the user resized, then the actual column widths end up different from what they were before.
If instead I set all column widths explicitly, then all columns behave as though they had been resized by the user, which is not ideal.
Is there a way to restore the column widths that gets around these problems?
It turns out that expand interferes with fixed_width. In my case, the solution was to set fixed_width and expand=false on columns that the user resized, and expand=true on the others.

How to fix the number of rows while designing pdf using iText in java

I am creating one pdf file showing a list of all employees and their salaries. At the end of the page it is showing the total of all salaries.
I am using a for loop to add multiple rows to table.
The problem is:
at the end the row, the total salary doesn't fit on the same page and it is shown on the next page.
So is there any way that I can calculate the height of the page and then fix the height of each cell? And then accordingly, limit the number of rows.
So that at the end of the page, I can show the total number of rows and further record from next page.
Calculate the height of the page: well... you decide on the size of the page when you create a Document object. You can choose any size you want.
Calculate the height of a PdfPTable: that's explained in chapter 4 of my book. When you create a PdfPTable, you add PdfPCell objects to an object that only exists in memory and that doesn't know anything about page size. By default, the width is expressed as a percentage of the available width of the page to which you'll add the PdfPTable. Only when you add the PdfPTable to a specific Document, the exact width and the height will be calculated (which is too late for you).
If you want to know the height in advance, you need to define an absolute width (not a percentage). Tables with the same content and a different width will have a different height. Defining an absolute width is done like this:
table.setTotalWidth(width);
table.setLockedWidth(true);
In this snippet (taken from the TableHeight example), width equals the width of the page minus the left and right margin. You're defining the width of the page and the margins upon creation of the Document object. By default, the page size is A4, so the default width is 595 user units and the default margins are 36 user units.
So, one way to solve your problem, would be to add rows in a loop and calculate the height of each row with the getRowHeight() method or the height of the complete table with the getTotalHeight() method (both methods will return 0 if you omit setting the total height). If you see there's not enough space to add the summary row, you can use the deleteLastRow() method to remove that last row and to create it anew in a new table on the next page.
That's one solution. Another solution could be to use table and cell events, but that's more difficult to explain.