How to adjust column width to content in server-side Ag-Grid React - ag-grid

I have a "server-side" Ag Grid in my React application, and I want to adjust the columns width to the row content width. I want to use the following function
autoSizeAllColumns = (skipHeader?: boolean) => void;
But whenever I call it passing "true" as an argument, meaning I don't want it to take the headers into account when sizing the columns, it shrinks all columns (I suspect it is trying to adjust the columns to an empty content).
I have tried to call
autoSizeAllColumns(true)
in several ways, including inside
onFirstDataRendered
but I always get the same result.

Related

Is it possible to have multi/custom field type inside a w2ui grid column with inline-editing for each type based on cell value?

Is it possible to have a grid column containing multiple types inside of it based on the value of a cell? Where each cell is rendered based on value. For instance, with in the same column a cell could be of type 'text' or 'datetime' or 'list' etc... and for each type I can use built in inline-editing? See image illustration below. Basically a key/value editor where the value column need to contain more than one 'type. Please post a sample answer.
It's possible, but you cannot rely on standard funtionality.
The idea of a w2grid is to assign a renderer to a column and render all cells of the same column in the same way.
You could implement a render function for your column and then generate the HTML for each cell based on those arguments:
http://w2ui.com/web/docs/1.5/w2grid.columns
Or you could override getCellHTML() for your grid.
Have a look at the implementation of getCellHTML() to see what awaits you if you want to customize it:
https://github.com/vitmalina/w2ui/blob/master/src/w2grid.js#L7396
Although it was a hack solution I ended up creating multiple grids aligned vertically each with a property & value column but the value column's 'type' attribute is different for each grid based on the w2ui framework out of box functionality I Desired for it. Each Grid is also separated by the header without padding to give it a feel like it is one grid. See Image below. now obviously the draw back of this is you cannot sort on all the fields but this is not required in my use case.

How to add space between rows in NSTableView

I'm trying to add spaces in between rows in an NSTableView, like how it looks here.
Currently, however, my rows look like this, with 0 spacing between them.
Is it possible to add these spaces? I found this post on how to do it, but that's for UITableView, and I don't think you can add sections with NSTableView. Another thing I tried was using intercellSpacing on the table view, like so:
tableView.intercellSpacing = NSSize(width: 0, height: 80)
However, that just increases the height of each row rather than increase the space between them.
Lastly, I looked into drawSeparator, which seems promising but has limited documentation. Would extending NSTableRowView and overriding the drawSeparator method work, basically by drawing in a blank space as the separator? If so, how would I go about making my table view use my custom row view class?
If none of these options work, I'd also be open to faking the effect, maybe by having the actual content of a row be smaller than the row itself and using the remaining space as the padding between rows. However, I'm not sure if this would work, given that right now I'm using NSShadow, which highlights the boundary of each row.
Found a way to work around this issue. Before, each row consisted of two columns, one for the text fields and one for the buttons. However, I've changed it by putting all the text fields and buttons into a single column, that way there's only one cell per row. I then can apply the NSShadow and other styles to the NSTableCellView rather than the NSTableRowView. This means that I can now use intercellSpacing to create vertical spacing between cells:
tableView.intercellSpacing = NSSize(width: 0, height: 80)
The rows are still touching, but I've disabled the borders/highlighting on them so you can't actually see them. The cells, on the other hand, are visible, and you can adjust the spacing/styles on them as necessary.

Modify an ag-grid row after rendering

I need to slightly modify a ag-grid row after it has been rendered. In ag-grid, the actual HTML elements are not necessarily persistent, so manually-set styles may fall off.
For one thing, I have to modify the selection checkbox to set its tabindex to -1. This can technically be done in the cellRenderer callback, although it looks quite hacky. (The checkbox can be found at params.eGridCell.children[0].children[0].wrappedElement.)
But I also have to add a CSS class to some rows to highlight them based on external criteria. I haven't found a way to do this at all.
The best solution would seem to be using some sort of after-rendering callback, but to my knowledge no such thing exists.
I found a couple of related questions, but they were both resolved via cellStyle, which would not suffice here:
Row formatting in ag-Grid
How to provide a background color for an entire row in ag grid based on a certain value in a column?
You have not 1 but 3 options:
getRowClass(params):
Callback version of property 'rowClass'. Function should return a string or an array of strings.
getRowStyle(params):
Callback version of property 'rowStyle'. Function should return an object of CSS values.
processRowPostCreate(params):
Allows you to process rows after they are created. So do final adding of custom attributes etc.
In this last one you have the row in params.eRow.
All taken from https://www.ag-grid.com/javascript-grid-callbacks/index.php

ListGrid with auto size - missing columns

I'm using smartgwt ListGrid. The problem appears when it's empty, and if i manually set columns width, i can get some columns clipped in the view port and there is no horizontal scrolling so I can't access them.
But if I add an empty record, the scrollbar appears. I've fixed it by adding
setAutoFitData(Autofit.HORIZONTAL);
setAutoFitMaxColumns(3000);
setOverflow(Overflow.AUTO);
But I need to add some freezed columns to my listGrid. I'd like to use setFrozen(true) method, but its not compatible with setAutoFitData(Autofit.HORIZONTAL);
What I need is
to show a scrollbar if columns are out of the view port, even when list grid is empty.
some first columns must be frozen.
Everything works with the base List Grid with no additional options. But when i set
setShowEmptyMessage(false);
my scrollbar disappears.
Kind of workaround i've found:
setShowEmptyMessage(true);
setEmptyMessage(" ");

stretch a textField to a max height in jasper reports

I think this is more of a general issue. I would like to use a textfield that gets dynamic data and doesn't stretch more than a given max height. For instance, I have a textfield that, if it gets text that fits in one line, the textfield will be one line height, and i have other elements under it, that will move up with float positioning. Or, if I want a 3 line max height and if the text exceeds that space, then the rest will be trimmed.
I don't want to use java expressions to trim that text, as it is not always accurate. I am new to jasper and I am trying to know if there is any way to do this. I did a lot of searches, but maybe there is something that i missed, and i hope someone can help me. Thank you
I managed to solve this by extending net.sf.jasperreports.engine.fill.TextMeasurer and overriding initialize() method; also I had to extend net.sf.jasperreports.engine.util.AbstractTextMeasurerFactory and override the createMeasurer() method.
Now, whenever I want to have max # of lines, with no overflow, I add a property to that text field (e.g. maxLines) which is being passed to my custom TextMeasurerFactory. I hope this helped you.
We had a similar problem at work with JASPER Reports 4.5, where we had an invoice with a header and a table. We wanted the header to have dynamic height based on the lengths of certain fields (like address, partner name, etc,), but not more than a critical limit, otherwise the header will push the table and thus making a mess by splitting it across multiple pages. Also, the invoice shouldn't exceed 1 page.
We eventually had to move the header in the background section, where we also put a background for the table consisting of vertical lines (so it will extend to the end of an A4 page) and a white opaque square.
This way, if the header exceeds the max height it will go underneath the table's background, cropping the text. This was the desired effect we were looking for.
Sounds crazy, but it worked ...