Is there a macro for data tables where we can provide columns and data and it creates table on page?
Asked by Ahmad Raza:

I have a requirement to programmatically add a table similar to html tables on a confluence page. I know I can add an html table in the html macro but i don't want that. Is there another option besides that?


Answers:
author: Sven Schatter _Lively Apps_
body: Hi Ahmad,

I'm not quite sure I understand your question correctly. Do you have data somewhere (e.g. in a Database or accessible via REST) and want to display it in a Confluence page as a table? Or do you want just a static table? Maybe you could give an example of what you mean. :)

Also: are you on Server or Cloud?

Cheers,  
Sven

comments: author: Ahmad Raza
body: Hi Sven,

I have an application which creates and updates pages on a space in confluence. So, I have data on my application server. I want to create a table on confluence using that data and using REST calls of confluence. For example, is there any option or endpoint where I can pass in the data and column names and page Id and confluence creates and populates the table automatically for me on that page.

Thanks.


author: Sven Schatter _Lively Apps_
body: Hmmm... I'm not 100% percent sure I fully understand what you want to do yet, but it does sound like our app [PocketQuery](https://marketplace.atlassian.com/apps/1211199/pocketquery-for-confluence) could be the solution to your problem. (You didn't say whether you're on Server or Cloud - if you're on Cloud you can pretty much stop reading here, because it's not available there yet)

With PocketQuery you could define a [REST Query](https://help.livelyapps.com/documentation/display/PQDOC/Full+REST+API+Examples) that fetches data from your external server. You can then insert the PocketQuery macro into page which will execute and render your REST Query into a table.

The only thing is that depending on the layout of your data, you might need to write a PocketQuery Converter or a PocketQuery Template. But I can help you with that, if you want to do that. :)

Let me know if this actually sounds like a solution to your problem of if you want to do something else!

Cheers,  
Sven


author: Ahmad Raza
body: Let me explain with help of an example. For example, I have data like this in my application server e.g. column names: name,id,date and I have arrays or lists of values for these three columns. Now I want to create a data table on a confluence page programmatically using this data. So, is there a macro available for this where I can pass this data as parameters to macro.

I looked here for all the macros available: <https://confluence.atlassian.com/display/CONF55/Working+with+Macros>. But I didn't find one for simple data table or html table.

PocketQuery does sound like a possible solution, but if there is a macro other than that, it will be really helpful.

And yes, I am on server not on cloud.

Thanks.


author: Sven Schatter _Lively Apps_
body: Hi [@Ahmad Raza](/t5/user/viewprofilepage/user-id/3566026),

sounds really like PocketQuery would exactly do what you need. There definitely isn't a standard Confluence macro that does anything like that. You will need some kind of Marketplace App or code a User Macro or Custom Plugin yourself.

Bonus: You can also use PocketQuery to connect to JDBC databases and display SQL results in your Confluence, using a macro. Maybe that's even a better approach in your case (depending on whether you have access to the database).

Cheers,  
Sven


author: Ahmad Raza
body: Alright, Thank you for your help Sven.