Allow export of specific columns from Table Grid table
-
Simone Chen While the Table field in Jira may have all the necessary details / columns for given uses cases, oftentimes upon export users may only have the need for a subset of the columns (due to the final audience for consumption).
Take for instance, in Jira, the team members may be working on the ticket and adding all necessary details to perform work in the table but when exporting out of the system for manager review, the manager may not need all the details in all columns.
-
Aron Gombas Simone,
This is doable even if it may not be super-intuitive.
The implementation of the Better PDF Exporter - Table Grid integration is based on:
- getting the field value from Table Grid as an HTML string
- pre-processing the HTML string
- converting the HTML string to FO and inserting the FO back to the template
If, between step 2 and 3, you take the HTML string and remove the unwanted columns from the HTML markup, then you have solved the problem!
Does this make sense?
-
Simone Chen Thank you Aron! Conceptually it makes sense I think, we'll give this a look and let you know if there are any questions.
-
Simone Chen Hi Aron,
Do you have a sample or something similar to the approach you've mentioned?
Unfortunately we're not certain we're interpreting the code the right way.
Thank you.
-
Aron Gombas If you look at the code of the cfValue() macro in the top of the template you will find this snippet.
I marked the point where to insert your post-processing code that removes the unwanted parts:#elseif($customFieldTypeKey == 'com.idalko.jira.plugins.igrid:tableGridCFType')
#set($htmlMarkup = $moduleDescriptor.getColumnViewHtml($customField, $customFieldValue, $issue, $map.build(), $fieldLayoutItem))
## remove all <div ...> tags
#foreach($j in [1..10])
#set($s = $stringutils.indexOf($htmlMarkup, "<div"))
#if($s != -1)
#set($e = $stringutils.indexOf($htmlMarkup, ">", $s))
#if($e != -1)
#set($e = $e + 1)
#set($htmlMarkup = $stringutils.remove($htmlMarkup, $stringutils.substring($htmlMarkup, $s, $e)))
#end
#end
#end
## remove all </div> tags
#set($htmlMarkup = $stringutils.remove($htmlMarkup, "</div>"))
#set ($htmlMarkup = $htmlMarkup.trim())
##
## <--- at this pont the $htmlMarkup string contains the table, you can remove rows, cells, etc. by manipulating the string
##
$pdfRenderer.htmlToFo($htmlMarkup)I can't give a working example, but with minimal HTML skills and using the $stringutils class (see: https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringUtils.html), it should be piece of make to modify it.
(As an alternative, you could even XML-parse the HTML into a DOM object, manipulate that, and then serialize that back to string again. But it seems an overkill to me.) -
Simone Chen Thank you Aron. We do have some code in place but it looks like the plugin isn't recognizing the Idalko class.
Please see below:
#set($pluginAccessor = $componentAccessor.getPluginAccessor())
#set($dataManagerClass = $pluginAccessor.getClassLoader().findClass("com.idalko.jira.plugins.igrid.api.data.TGEGridTableDataManager"))
#set($tgeGridDataManager = $componentAccessor.getOSGiComponentInstanceOfType($dataManagerClass))
#set($columnNames = ["Column 1", "Column 2])The error that is returned is:
org.apache.velocity.exception.MethodInvocationException: Invocation of method 'getOSGiComponentInstanceOfType' in class com.atlassian.jira.component.ComponentAccessor threw exception java.lang.IllegalStateException: Unable to resolve component
Thank you
-
Aron Gombas Simone, please open a support ticket and attach your full code so that we can have a look.
-
Simone Chen Hi Aron,
Thank you I've gone ahead and created Request #4717
-
Frank Yu Hi Simone,
I have the same requirement as yours. Did you fix the custom column issue? If yes, would like to share your complete scripts here for reference? I appreciate for that.
-
Stanislav Petr Hello guys. It this solution funcional on newer versions? I dont want to create new ticket. Thank you. S.
-
Levente Szabo Hi Petr,
This feature request is still gathering interest. If you have a specific question, please do open a support ticket.
Thanks!
11 Comments