Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

41 comments

@Greg Blisardunfortunately, you need to have the Confluence System Administrator privilege to manage user macros.

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>

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

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.

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

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 Nov 04, 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

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?

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

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

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.

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!

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

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

Thanks,

Shankar.

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

Comment

Log in or Sign up to comment
TAGS
Community showcase
Posted in Confluence Cloud

Please tell us how you use Confluence space settings

Hi there, a few of us at Atlassian would love to learn about how you use "space settings" functionality in Confluence. A facelift to the space settings is long overdue and we want to start with impro...

313 views 11 8
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you