Showing number of comments in (AppWithinMinutes) livetable

Hey everyone,

I’m looking to add a collumn with the count of the number of comments per instance of an appwithinminutes class.

I’ve come as far that I can get the number with

$doc.getComments().size()

and worked through the Livetable Macro (XWiki.org) documentation, unfortunately I have yet to figure it out.

Is this possible? Alternative is that I make a table on the parent page with all pages with comments but I think I’d prefer the comment count in the livetable option if it’s possible.

Hi @Wardenburg,

What you can try is to add a new computed field property to your class to keep the number of comments. Then, in the livetable, you would only need to add the column for the new property and display its value.

Hope it helps,
Alex

1 Like

It definetly helps, thanks a ton @acotiuga !

after adding the computed field and the columnsproperties:

`{“type”:“number”,“html”:true,“match”:“partial”}

the table shows as expected, excellent!

One more challenge before its exactly good however; the calculated fields get put in

tags (hence the html: true) value. This doesnt matter much until I try to sort/filter the collumn , which doesnt work now. (for some reason it wont partially filter just the numbers in strings either.

I’ve fiddled around a bit with the custom display property Which variables can I use in the "Custom Display" field? (XWiki.org)

and also looked at how to convert strings to ints in velocity. Unfortunately I cant quite figure out how I can store the computed fields as integers. (assuming that that will allow me to sort/filter the collumn as expected).

Any ideas for this final obstacle?

It is not possible to make this column sortable/filterable because the new field is not a metadata field of the document, persisted to the database, but a dynamic field computed from different sources - velocity script. Livetable filters work directly on the database, meaning that they translate into sql conditions.
If you want to explore more, you can go for a number property and use an event listener to update its value whenever a new comment is posted on a page. With this approach you would be able to do any operation in livetable.

1 Like

That is so insightfull, I get what’s going on now. Thank you for taking the time to share your knowledge with the noobs @acotiuga .

I will definetly add learning to and Writing an Event Listener (XWiki.org) to my new years resolutions!

Happy holidays and thanks again!