The Admin's tale - User Macro filtering a Confluence table

46 comments

Thomas Kreft
Contributor
May 9, 2018

@[deleted]unfortunately, you need to have the Confluence System Administrator privilege to manage user macros.

Rahul Savaikar June 12, 2018

Is it possible to exclude the first row and first column from the search?

 

Currently, I use the below multi-search code:

## Macro Name: filter-all-tables
## Macro Title: Filter all tables
## Category: Confluence Content
## Macro has a body: N
## Body processing: None
##
## Source: https://community.atlassian.com/t5/Confluence-articles/The-Admin-s-tale-User-Macro-filtering-a-Confluence-table/ba-p/459369
## Date implemented: yyyy-mm-dd
## Implemented by: xxx.yyy@zzz.com

## @@param FilterID:title=FilterID|type=string|required=true|desc=ID [a-z,A-Z,0-9
## @param Label:title=Label|type=string|required=true|desc=Label
## @param Class:title=Length of the input field|type=enum|enumValues=short-field,medium-field,medium-long-field,long-field,full-width-field|default=long-field
## @param ColumnNumber:title=Column Number|type=string|required=true|default=-1|desc=Specify the column number or "-1" for the entire row

<form class="aui">
<input class="text $param0" type="text" id="searchInput" placeholder="Filter all tables (case insensitive)">
</form>

<script type="text/javascript">
AJS.$("#searchInput").keyup(function () {
var jqry = AJS.$
var rows = jqry("tr").hide();
var searchData = this.value;
if (searchData.length) {
var data = searchData.toLowerCase();
jqry.each(data, function (search_idx, str) {
rows.filter(function(row) {
return $(this).text().toLowerCase().indexOf(data) >= 0;
}).show();
});
} else rows.show();
AJS.$('thead tr').show();
});
</script>
Sid Varma
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 2, 2018

How do I download this feature and implement on my confluence wiki space?

Patrick Cartier [Candylio]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 2, 2018

Hi @Sid Varma,

Welcome to the community!

You need to add the code as a user macro in your confluence instance.  Here are instructions on how to write a user macro:

https://confluence.atlassian.com/doc/writing-user-macros-4485.html

I think @Thomas Schlegel's instructions are pretty good though, he includes the code, and instructions on how to get it going.  If you follow some of the comments you can see some nuances that others have input.

Thu Nguyen
Contributor
October 11, 2018

Many thanks Everyone and a big thank you to Thomas S, Thomas K and Alloisio. Your scripts are great and very helpful. I use Thomas K script as it simple and solves our problem.

Like Thomas Kreft likes this
Thu Nguyen
Contributor
October 31, 2018

If any special characters : open and close bracket (  ), underscore  _ , ampersand & are used in page name, I will get the error page as below:

Table-filter-error.PNG

Deleted user November 4, 2018

Hello, 

I have used the table filter macro provided by @Thomas Schlegel. Thank you!

Unfortunately I got some complaints that it is not case insensitive, so I wanted to have multi-word search and case insensitive. 

I made such modifications to script:

<script type="text/javascript">
AJS.$("#searchInput").keyup(function () {
var jqry = AJS.$
var rows = jqry("tr").hide();
if (this.value.length) {
var data = this.value.split(" ");
for (i = 0; i < data.length; i++) {
if (data[i]){
rows.filter(function (){
return $(this).text().toLowerCase().indexOf(data[i].toLowerCase()) >= 0;
}).show();
}
}
} else rows.show();
AJS.$('thead tr').show();
});
</script>   

 Let me know your feedback.

Cheers!

Anna

Like # people like this
rohit patel April 9, 2019

Hi All,

Thank you for the above solution. It really helped me with using search feature within a long confluence table. 

I also wanted to ask if there is any similar customisation that we can use to have a drop down filter for one of the columns in the same table where we added the search bar?

 

It will be of great help as i have a long table with about 500+ rows. It would be nice if i can have a drop down filter also. 

Any suggestion will be appreciated. 

 

Regards,

Rohit

Deleted user May 24, 2019

Thanks @Thomas Schlegel  @[deleted] 

 

Do you guys have other useful user macros?

Jose_Venceslau
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 29, 2019

Just in case someone needs multi-word, case insensitive, with intersection of all words instead of union of all words, I've adapted the script bellow.

Thank you very much to all that provided the previous code :)

<script type="text/javascript">
AJS.$("#searchInput").keyup(function () {
var jqry = AJS.$
var rows = jqry("tr").hide();
if (this.value.length) { 
var data = this.value.split(" ");
  rows.filter(    function () {
   all = true;
  for (i = 0; i < data.length; i++) {
     if (data[i]) {
        all = all &&  ($(this).text().toLowerCase().indexOf(data[i].toLowerCase()) >= 0);
       if (!all) { break; }
     }
}
 return all;
  }).show();
}
else rows.show();
AJS.$('thead tr').show();
});
</script>
Like # people like this
John Nguyen
Contributor
December 30, 2019

Hi Thomas Schlegel

  I have a use case quite close to what you described.  My scenrio is this:  I have  custom form/template/page created under the Knowledge Space.  The custom form has two fields: first_name and last_name. I'd like to create a page with (1) an input field where the user can enter the record ID of a record which contains a customer's first name and last name. (2) a button called "generate PDF" button which will take the lira record ID as an input, looks up the record, extract the first_name value and the last_name value then populate these two values into the predefined template/page.  Once the values are inserted properly into the fields on the page, the user then can export the from as a PDF file.

  Based on what your described, I think it is every close to what I want but I'm sure how to go about doing it.  Would you give me some tip of how-to?

  Thanks

  John Nguyen

Yogesh Mude
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 20, 2020

Hello Team,

Actually, i have jira macro which can display the jira filter content in table format to confluence page.

Now, in table there is a column called "Billing status" it holds three values ie. Running, Started, Completed.

So if the Billing status is Running then it show in YELLOW, if the Billing status is Started then it show in RED and Completed in GREEN.

I tried to search around it and to achieve this i need to write an user macro..so anybody has the basic code that can capture the table content, so pls share, it will help and will do the changes to it as per the conditions.

Ramya Nimmu {Appfire}
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 8, 2020

Hi, @Thomas Schlegel 

I have a piece of very minimal knowledge of Confluence, So I would like to seek your help on the requirement which I have currently. I'm reorganizing the support structure for my team and as part of "typical" systems management, the L1 resources need to run a health check and check the License details in Confluence. But the team will not be having Admin permissions.

When I was looking for options, I came to know about User Macros in Confluence. So I'm wondering that can we achieve this by creating user macro. If so, Could you please guide me with the code.

Your help is highly appreciative!

Thanks in Advance!

Deleted user June 8, 2020

Hello, 

I tried that macros with Confluence V7.4. It does not work.

It always shows the full table, not only the matching lines.

Has anybody a hint for me?

Thanks 

Manfred Wiplinger

shankar_kalagadandu October 14, 2020

Hi @Thomas Schlegel , Can you please give the code for dynamic results count based on search in a table?

Thanks,

Shankar.

Gonchik Tsymzhitov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 2, 2021

Wow, no need to buy add-on, just add the user macro :)

Anna Hummel
Contributor
March 6, 2023

@Thomas Kreft  , I just tried your script but unfortunately there is error coming. Any idea why?confluence table filter.png

Like Helge Hasund likes this
Thomas Kreft
Contributor
March 6, 2023

@Anna Hummel did you follow @Thomas Schlegel 's initial how-to to create the user macro? If you still need assistance, please post a screenshot of your macro definition.

Anna Hummel
Contributor
March 6, 2023

@Thomas Kreft I tried, but wasnt successful. Here are my screenshots. Thanks!conf screenshot 1.pngconf screenshot 2. png.png

Like Helge Hasund likes this
Thomas Kreft
Contributor
March 6, 2023

@Anna Hummel Sorry! I found (and fixed) the error in my comment from 2017-08-03: 

## @@param 0:title=Lenght of the input field|type=enum|enumValues=short-field,medium-field,medium-long-field,long-field,full-width-field|default=long-field

...contains an extra "@". It should be like this:

## @param 0:title=Lenght of the input field|type=enum|enumValues=short-field,medium-field,medium-long-field,long-field,full-width-field|default=long-field

Hope this helps!

Like Anna Hummel likes this
Anna Hummel
Contributor
March 22, 2023

@Thomas Thanks, it worked perfectly! Very much appriciated!

Like Thomas Kreft likes this

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events