How to get table id filtered by Table Filter from HTML page source?
Asked by Aster:

I am trying to use HTML macro to extract data from "Confiforms TableView combined with **Table Filter** " macro and show the content in plain text to serve as a table summary.  
Like, we have a table of everyone's expense (filtered in some condition), and we'd like to be able to put a sentence like: "UserA spent the highest amount in last month."

However, seems like the table id in the page source is not fixed, and it changes every time when the page is refreshed. And I tried using "data-cf-form", but it will return unfiltered data.

Wondering if there's a way to come out the summary sentence?

Thanks!


Answers:
author: Stiltsoft support
body: Hi [@Aster](/t5/user/viewprofilepage/user-id/5219143) ,

Not sure if we got your ticket in our JSM or maybe it was some other customer (we got a similar question there), so I duplicate some hints here for other people to see if they come across this question: you may try to find your table and get the required data as plain text using javascript

tfTableSelector = "table.tf-macro";  
document.querySelector(tfTableSelector).innerText;

In your script you need to specify the tfTableSelector, and the innerText option returns all the data, even the filtered out rows.

Note that our app also doesn't set or change any table IDs and table data.

And maybe this hint may come in handy - you can find and show specific cells as plain text using javascript and Table Transformer macro:

![Mon 2-1.png](https://community.atlassian.com/t5/image/serverpage/image-id/276247i9DFD8A2461C08A5B/image-size/large?v=v2&px=999 "Mon 2-1.png")

SEARCH AS @Cells RETURN(@Cells-\>\[1\]-\>key) FROM T1;

![Mon 2-2.png](https://community.atlassian.com/t5/image/serverpage/image-id/276248i2D47E228A34E04FA/image-size/large?v=v2&px=999 "Mon 2-2.png")

Hope this helps your case.

comments: author: Aster
body: Hi [@Stiltsoft support](/t5/user/viewprofilepage/user-id/5062270)

yeah I am the one asked this question in your JSM. For the first solution, using tfTableSelector, I just can't figure out which element I should use to get the filtered table. I think I will just give up on this...

The second solution is great! But if I'd like to add some words in front of the search result, like "Here is ++2 - we want to find this cell++ ." And combine 2 search results, like "++2 - we want to find this cell++ and ++1,2,5++." Could you advise how to get them by Table Transformer?

Thank you!


author: Stiltsoft support
body: Hi [@Aster](/t5/user/viewprofilepage/user-id/5219143) ,

You may try the following SQL query:

SEARCH AS @Cells RETURN  
(@Cells-\>\[1\]-\>key AS 'Some comment 1',  
@Cells-\>\[1\]-\>Platform AS 'Some comment 2')  
FROM T1;

![Mon 3-1.png](https://community.atlassian.com/t5/image/serverpage/image-id/277446iF126E4ABADE6414C/image-size/large?v=v2&px=999 "Mon 3-1.png")

Or if you want to have several entries as plain text, you may reuse your source table several times with the help of the [Table Excerpt/Table Excerpt Include](https://docs.stiltsoft.com/tfac/dc-server/how-to-use-table-excerpt-and-table-excerpt-include-macros-42241623.html?utm_source=atl_community&utm_medium=answer&utm_campaign=table-filter-traffic-sources&utm_vendorID=1216111) macros and use several Table Transformer macros with the queries from the previous answer.

So, you just manually type your description (for example, "Some comment 1") and then extract the required info using the Table Transformer wrapped above the Table Excerpt Include macro.


author: Aster
body: Hi [@Stiltsoft support](/t5/user/viewprofilepage/user-id/5062270)

Can I simply add a few words, like "Here is", in the plain text result?

I am asking because the result I get now will be in the new line, so it doesn't look like a complete sentence to users, which makes it weird...


author: Stiltsoft support
body: You may use the second internal Table Transformer macro with this kind of query:

SELECT  
"Some text we want to add " + 'key' + " Some thext we want to add" AS 'key',  
"Some text we want to add " + 'Platform' + " Some thext we want to add" AS 'Platform',  
"Some text we want to add " + 'Another' + " Some thext we want to add" AS 'Another'  
FROM T\*

Here we add some text before and after the cells' contents.

![Mon 4-1.png](https://community.atlassian.com/t5/image/serverpage/image-id/277494iE4DC4DB4AEC22B74/image-size/large?v=v2&px=999 "Mon 4-1.png")

Then you use the first SQL query in the external Table Transformer macro and get the specific cell's contents.

My screenshot was taken for Confluence Cloud, so I nested my macros via the Table Toolbox macro. On Server/Data Center you wrap your macros directly one into another.


author: Aster
body: Thanks a lot! It works well.

But if I'd like to add a space in front of some text, like: " Some text we want", it will just ignore the spaces.

I tried a few way to add the space but still not able to. Could you advise how it can be done in the Table Transformer macro? Thank you.


author: Stiltsoft support
body: You may use some visible symbols that are not ignored by HTML, for example, a series of underscores:

"Some text we want to add______" + 'key' + "______Some text we want to add" AS 'key'

They will be shown as they are.


author: Aster
body: Ok, got it. Thanks so much!


author: Alex Medved _ConfiForms_
body: Hi

Cannot tell much about the "table id", as this does not sound like something from ConfiForms app... but to approach your problem I would try to use the ConfiForms ValueView to get the aggregated and filtered number. I believe that should work

Or a separate TableViewMerger macro to show aggregated numbers

Alex

comments: author: Aster
body: Hi [@Alex Medved _ConfiForms_](/t5/user/viewprofilepage/user-id/781630),

By "table id", I mean the one that can be found in the page source. We are trying to capture the data in a filtered TableView macro, and put them in plain text as summary using HTML codes. Is there a example that ConfiForms ValueView might also be able to do that? Thanks!

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/275701i2B356EFC025D03DA/image-size/large?v=v2&px=999 "image.png")


author: Alex Medved _ConfiForms_
body: If you need something unique and constant you can add a "class" to CSS parameter

Something like

class:iamunique

And then access the table using the class, AJS.$('.iamunique')

Alex


author: Aster
body: We can get the unique class from your suggestion. Thanks.

However, it will return the whole table instead of the filtered one...

Would you help to provide some suggestion on how we can capture part of the filtered table and put them in plain text as summary?


author: Alex Medved _ConfiForms_
body: Sorry, I dont know anything about the "filtered one". Can help with ConfiForms specific questions... As I understand this is something what TableFilter plugin does


author: Aster
body: No worries. Thanks for your feedback.

I edited the question so people familiar with Table Filter might see this.


Tags: confiforms

confluence-server

filter

server

table