Is there any way to divide one result from PocketQuery on multiple tabs?
Asked by BB GG:

Hi, I need help (:   

my company uses PocketQuery. I created six really simple "selects". Each of them I put into six tabs on one page. Each of them uses the same table, just different columns.   
The problem is that time of loading the page is too long, up to 1 minute. The queries are just "selects" without generating any big data - just from table with ready to read data. The table has just about 80 rows.   

I read about additive "Cache for Confluence", but maybe there is a way to do one select with all data from the table and then divide them into each tab?


Answers:
author: Sven Schatter _Lively Apps_
body: Hi [@BB GG](/t5/user/viewprofilepage/user-id/4325395),

Yes, there is! Thanks to [Templates](https://help.livelyapps.com/pocketquery-for-confluence-server/Templates.824377352.html), you can basically do anything with PocketQuery that you could do on a normal website. No additional apps required. :)

This is for example a Template that renders 2 tabs, and then calls the "default template" which renders a table in the first tab, and also another template on the second tab (which could render your *$result* differently):

```
$webResourceManager.requireResourcesForContext("com.atlassian.auiplugin:tabs")

<div class="aui-tabs horizontal-tabs">
  <ul class="tabs-menu">
    <li class="menu-item active-tab">
      <a href="#tabs-example-first">Tab 1</a>
    </li>
    <li class="menu-item">
      <a href="#tabs-example-second">Tab 2</a>
    </li>
  </ul>

  <div class="tabs-pane active-pane" id="tabs-example-first">
    <h2>This is tab 1</h2>

    ## Inside here, call things like $PocketQuery.template()
    ## Or $PocketQuery.renderPocketQueryMacro()
    <div>$PocketQuery.template("default")</div>
  </div>

  <div class="tabs-pane" id="tabs-example-second">
    <h2>This is tab 2</h2>

    ## Inside here, call things like $PocketQuery.template()
    ## Or $PocketQuery.renderPocketQueryMacro()
    <div>$PocketQuery.template("dab6316a-f02c-42b4-b9a8-33fbdce52744")</div>
  </div>
</div>
```

Here's what that looks like:

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

If you have any questions, let me know. :)

Cheers,  
Sven

comments: author: BB GG
body: Thank you [@Sven Schatter _Lively Apps_](/t5/user/viewprofilepage/user-id/1169931), it can be good way.  
Please, read my example that I mentioned in my reply to Katerina.   
Will it be good idea to make an "invisible tab" with all columns (select \* from theTable) and then operate on $result in other visible tabs?   
Maybe you have better idea? Is it possible to get specific columns from $result and put them simply into a table?


author: Sven Schatter _Lively Apps_
body: Hi [@BB GG](/t5/user/viewprofilepage/user-id/4325395),

Sorry for taking so long to respond! The last days have been quite busy for me as we launched 2 new apps on the Marketplace. :)

Getting back to your question, yes, you can use this exactly to do what you described below. This is going to be a long answer as I will need to paste you lot of code, but it's really not that complicated. Consider a simple result like this:

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

I now create 2 PocketQuery Templates that only render certain columns out of the **$result**. For example:

Template 1: Only **Content ID + Title**

```
<table class="aui confluenceTable pocketquery-table">
<thead>
  <tr>
    <th class="confluenceTh">Content ID</th>
    <th class="confluenceTh">Title</th>
  </tr>
</thead>

<tbody>
  #foreach ($row in $result)
  <tr>
    <td class="confluenceTd">$row.get("contentid")</td>
    <td class="confluenceTd">$row.get("title")</td>
  </tr>
  #end
</tbody>
</table>
```

Template 2: Only **Content Type + Version**

```
... same thing as above
just using "contenttype" and "version"
instead of "contentid" and "title"
```

Now we need a third Template that calls the other two and renders the tab navigation:

```
$webResourceManager.requireResourcesForContext("com.atlassian.auiplugin:tabs")

<div class="aui-tabs horizontal-tabs">
  <ul class="tabs-menu">
    <li class="menu-item active-tab">
      <a href="#tabs-example-first">Everything (Default Template)</a>
    </li>
    <li class="menu-item">
      <a href="#tabs-example-second">Template 1</a>
    </li>
    <li class="menu-item">
      <a href="#tabs-example-second">Template 2</a>
    </li>
  </ul>

  <div class="tabs-pane active-pane" id="tabs-example-first">
    <h2>This will display the complete result table</h2>
    <div>$PocketQuery.template("default")</div>
  </div>

  <div class="tabs-pane" id="tabs-example-second">
    <h2>This will only display the content id & title</h2>
    <div>$PocketQuery.template("<INSERT ID OF TEMPLATE 1>")</div>
  </div>

  <div class="tabs-pane" id="tabs-example-second">
    <h2>This will only display the content type & version</h2>
    <div>$PocketQuery.template("<INSERT ID OF TEMPALTE 2>")</div>
  </div>
</div>
```

This is the Template you want to assign to your Query. **Do not forget to replace the IDs inside the $PocketQuery.template calls!** :)

The final result should look like this:

![ATLCOM_2.gif](https://community.atlassian.com/t5/image/serverpage/image-id/137018iE36FE4EF0FC93D12/image-size/large?v=v2&px=999 "ATLCOM_2.gif")

And for all of that, you only sent one single Query to your Datasource!

Let me know if this helps. :)

Cheers,  
Sven


author: BB GG
body: Hi [@Sven Schatter _Lively Apps_](/t5/user/viewprofilepage/user-id/1169931)

I have been quite busy too :)

You're awesome, thank you! You helped me a lot. :))


author: Katerina Kovriga {Stiltsoft}
body: Hi [@BB GG](/t5/user/viewprofilepage/user-id/4325395) ,

Maybe you use the [Table Filter and Charts for Confluence](https://marketplace.atlassian.com/apps/27447/table-filter-and-charts-for-confluence?hosting=server&tab=overview) app in your company?

Its [Table Filter](https://docs.stiltsoft.com/display/public/TFAC/How+to+use+Table+Filter+macro) macro may come in handy for your case: create several filter views based on your "selects" (you'll work only with the one table) and save the filter URLs.

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

Then you'll be able to create buttons (links) for every "select" but using only one source table.

comments: author: BB GG
body: Thank you for your answer but your idea will be good for dividing rows, not columns. I need to divide it on several columns, different columns in each tab but from the same table.

For example:

I have table with columns: **name \| surname \| age \| height**

I need to make a page with tabs:

- **tab_** **Strings** where will be the table with **name** and **surname**only

- **tab_Numbers** where will be the table with **age** and **height** only   

In general I have a table with about 50 columns and 80 rows.   
I try to divide the 50 columns into smaller "category parts" like the String and Numbers. That's why I have the idea with getting data from one table for several tabs. Now I have 6 tabs and 6 queries, what is inefficient.


Tags: pocketquery

server

sql