Vaadin 23, converting inline Polymer template for grid columns renderes "NaN" instead of values - vaadin

I am trying to convert some inline polymer templates for grid columns, and the rendered value in the browser ends up as “NaN” for some reason.
So I simplified the template to reproduce the issue as the following:
grid.addColumn(LitRenderer.<SamplePerson>of("<span style='${item.stylename-0}'> test </span>")
.withProperty("stylename-0", dto -> "background-color: red"));
and the rendered value still says style="NaN". Is there something that I’m missing?
Steps to reproduce the issue:
Go to https://start.vaadin.com and add a Master-Detail view from the existing templates to the views.
Download the application and open it in your favorite editor.
in the com.example.application.views.masterdetail.MasterDetailView's constructor, add the column with a LitRenderer (you can copy the above snippet code as well).
Run the application, go to http://localhost:8080 and observe that the values for the manually added column hasn't been styled with a red background. Obviously, by inspecting the elements you could see the style="NaN" is rendered on the client.
Tested with V23.2.3 and V23.2.4 and the issue exists.

Nicely spotted by #leif-Åstrand, this was an issue regarding the -0 ending, which was being parsed as a mathematical subtraction in JS, and clearly resulting in "NaN".
The correct way of doing this kind of dynamic class or style values ("stylename-0", "stylename-1", ...) is to treat them as strings, so:
style='${item.stylename-0}'
should be written as
style='${item['stylename-0']}'

Related

Is it possible to create an angular material mat-table component with extra directives but still keep columns dynamic?

Is there a way to extend a mat-table that automatically includes the matSort directive (and other custom directives that interact with the columns, like filter) and still have the content inside hold the mat-sort-header directives?
<mat-table [matSortActive]="sortActive" [matSortDirection]="sortDirection" matSort>
<ng-content></ng-content>
</mat-table>
Here is an example: https://stackblitz.com/edit/angular-bxsavu.
I've tried creating a component on its own that just puts <ng-content> inside the <table> element, but that creates the error:
DwfTableComponent.html:1 ERROR Error: Missing definitions for header,
footer, and row; cannot determine which columns should be rendered.
at getTableMissingRowDefsError (table-errors.ts:48)
I've tried adding nothing to the entire template and just using the original CDK_TABLE_TEMPLATE (seen in the stackblitz link above), and this creates the error:
ERROR TypeError: Cannot read property 'viewContainer' of undefined
at DwfMatTableExtendedComponent.CdkTable._forceRenderHeaderRows (table.ts:854)
So it seems like I can't really get any traction on making this work.
The context of this all is that our site has many tables that need to sort, but we need developers to be able to write in what columns are sortable when writing the markup. If I can get this to work for MatSort, I can then turn and apply this to my own server side filtering component that behaves very much like the MatSort feature (has a customFilter directive in the <table> element, and within the <th mat-header-cell *matHeaderCellDef> spot there is a custom-filter-header directive). And then the big piece of it will be another feature that lets the table change what cells display (links or text) when the table is "paused" -- another feature that is controlled by the wrapper but needing to affect the inside content.
There are many other features in our current "table-wrapper" (search windows, exports, paging), but this one part of it has been a constant source of confusion. There's something a little broken feeling when I can't make a component that is made of two well known components and still leaves the table structure flexible. I'm sure I'm missing some piece of it, but this would greatly reduce the repetition of code for each table we have to write.
I've managed to get a table up and running, by using the original CDK_TABLE_TEMPLATE and extending the CdkTable found in the source code. From there, I put the MatSort directive on my own component, and fill things out like normal.
There were several bumps along the way. For starters, you have to import the CdkTableModule in your module. Next, you have to implement OnInit and call super.ngOnInit() just to get it to render. Styling then requires using the source code's table.scss, and even then, you need to tweak things just to get it to look right.
At this point, it feels like I'm roaming into hack territory, but there is traction finally, and I think after I figure out why the default sorting doesn't happen (as well as glyphs not appearing), I'll be on my way to expanding this to what I need. It's by no means ready for production, but the development has led to a quick education on angular limitations and abilities.
If anyone is curious, the same link https://stackblitz.com/edit/angular-bxsavu provides where I'm at right now.

Customize quoted strings in VS Code

The value side of attributes in HTML were very unreadable, too dark, making it especially hard to disseminate between class names in HTML, when using the dark theme on VS Code.
How do I change it to make reading more comfortable?
p.s. My "Tags" are very limited due to rep, but I'm so sure others have this question.
Here is how to accomplish this particular task.
Introducing [me to] a very useful tool: Inspect Editor Tokens and Scopes
Put cursor in, in this case, a quoted value string.
CNTL + SHIFT + P (open command palette).
Find "Developer: Inspect Editor Tokens and Scopes"
Note the textmate scope(s).
Use property: "editor.tokenColorCustomizations" → "textMateRules" to add new rule.
While I'm doing this directly on values in the JSON of settings - and changing quotes there at a high level, this also works with inheritance, so string.quoted.double.html would override the example shown in this screenshot (which applies to ALL double quoted strings), when editing HTML files. I find this useful for making my lint rules standout too.

DBText fields are shifted down when sending Report Builder report to Printer

I have a report template created in Report Designer. It is basically a RichText template with some DBText fields dropped on it. When I generate the report all the DBText fields are populated with data from database.
When I preview the generated report on screen it looks correct. But when I print the same report all DBText fields are shifted about one line down as on below screenshot:
If I remove RichText component and use only Labels and DBTexts then there is no problem with printing.
Has anybody faced the same issue in the past? How to solve it?
Note: I am using Delphi 5 with Report Builder 6.02 Enterprise.
As I found out the printing issue was caused by the RichText component used together with DBTexts components in the designer. It looks like Report Builder issue but I found two solutions for that:
You can remove RichText component from the template and use only Latels, DBTexts, etc. Printing will be fine in this case.
If you want to keep using RichText then you need to embed database fields inside the RichText Editor using angle brackets. You can see the example below:
Note, that it will only work when the “MailMerge” option is ticked (right click on the RichText component):
There is one limitation though. You can use only one dataset per report. However this can be solved by using subreports as for every subreport you can assign a different dataset (via Report -> Data menu).

Odt file, shown with all styles

I'm using odt file as some kind of template and Libre Office as tool to create this template. It usually works fine except one thing.
Let assume our odt file has a paragraph of text.
There is my text.
XML file may or may not look (seems random) like this (messy, not very good thing for for parsing or as a template):
<text:p text:style-name="P7">There is</text:p><text:p text:style-name="P7"> my text<text:p text:style-name="P7">.</text:p></text:p>
Sometimes it's (again seems random) like this (expected result, makes sense after all):
<text:p text:style-name="P7">There is my text.</text:p>
Is there any way to get rid superfluous xml tags? Or at least can user see a raw document in LibreOffice/OpenOffice to manually remove redundancy?
The key is to provide easy tool for a user, to detect and fix artefacts like this.
Have you tried Ctrl-M? If all formatting is defined in styles and style formatting is not manually overridden, it should not disturb the formatting but should remove redundant tags.
A tedious user process would be to cut and paste-special as text and apply style again.
Finally, a macro would definitely do the trick.

Filemaker: exporting a PLIST (for iOS)

I have a database which I want to export as an iOS compatible PLIST.
The work around I have come up with is to create a calculated field which adds the tagged padding and header and creates a report using these fields. I then export the preview of the report as a PDF, open the PDF in Acrobat Reader, select all text, copy and paste into XCode which recognises the PLIST format and all works as expected.
Is there a better way of doing this? (This seems a really convoluted way of doing things, high chance of error, etc.) The Export as XML option looks promising but I can't seem to join the dots.
Two ways that I can think of to do what you're trying to do. The most elegant way is probably the XML with XSLT export which you suggest. If you don't already know XSLT, though, you might try the following -- it sounds like with the calculated XML line you've already created, like this would be a simple change to your database:
Create a single new global field, say outputXML
Create a script, say plistCreator
In the plistCreator script:
Set outputXML to ""
Go to the first record you want to export
Loop through every record putting your calculated XML line into outputXML (set field outputXML to outputXML & ¶ & calculatedXMLLine)
Go to next record, exit after last
Export Field Contents (note that this is a different command than Export) for outputXML
The cleanest solution is to use the export XML with an XSLT for transforming the output. You'll need to know a little XSLT to do this, or at least be able to customize the examples from FileMaker.

Resources