Creating Tabs in Birt Report

veera_venkatesh178
edited February 11, 2022 in Analytics #1

I am creating a Report using Birt (Engine Api) with some Java code . now, I don't know how to create multiple tabs in a single Report. so,each tab represent one single Table in it . Can anyone please help me in this The following code i used

`
IReportEngine config = new EngineConfig();
config.setLogConfig("birtLogs", Level.WARNING);
IRegistryProvider ireg = RegistryProviderFactory.getDefault();
org.eclipse.birt.core.framework.Platform.shutdown();
RegistryProviderFactory.releaseDefault();
try {
org.eclipse.birt.core.framework.Platform.startup(config);
} catch (BirtException e1) {
e1.printStackTrace();
}
IReportEngineFactory factory = (IReportEngineFactory)org.eclipse.birt.core.framework.Platform .createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
engine = factory.createReportEngine(config);
URL rptFileUrl = null;
try {
rptFileUrl = new URL("****/Reports/*****.rptdesign");
} catch (MalformedURLException e1) {
e1.printStackTrace();
}
IReportRunnable reportRunnable = null;
try {
if (rptFileUrl != null) {
reportRunnable =
engine.openReportDesign(rptFileUrl.openConnection().getInputStream());

ReportDesignHandle designHandle = null;
designHandle = (ReportDesignHandle) reportRunnable.getDesignHandle();
}
} catch (EngineException | IOException e1) {
e1.printStackTrace();
}
while (designHandle.getBody().getCount() > 0) {
try {
designHandle.getBody().dropAndClear(0);
} catch (SemanticException e) {
e.printStackTrace();
}
}
ElementFactory designFactory = designHandle.getElementFactory();
try {
designHandle.setProperty("title", "Description");
/* creating Grid for the Tab */
createGrid(designHandle,designFactory);

/createTab(designHandle,designFactory);/ // I have to Implement for the Tab.

} catch (SemanticException e1) {
e1.printStackTrace();
}

engine.destroy();
designHandle.getBody().getContents().clear();
designHandle.close();

org.eclipse.birt.core.framework.Platform.shutdown();
try {
RegistryProviderFactory.setDefault(ireg);
} catch (CoreException e) {
e.printStackTrace();
}

     }
        } ) ;
      } catch (InvocationTargetException | InterruptedException e) {
        e.printStackTrace();
   }

`
I Used designFactory ,designHandle(above code) to create Grid and inserted data in it . I am expecting designFactory ,designHandle will Help to create multiple tabs as well but i don't know how to do it. please help me in with some code.

Comments

  • Birt does not have a Tab element.

    If you are generating an Excel file, there is a rendering option to put new pages on new sheets.

    If you are generating a web report, you can create your own web page with tabs, create a report for each table, and load the reports into the tabs as you would any other content. Alternatively, you can create a single report containing all of the tables and add a Text element at the top of the report. Write HTML and JavaScript code in the Text element to generate the tabs. Examples are easy to come by. In the tab onClick event, also add JavaScript code to change the CSS display properties for the tables to display only the table associated with the clicked tab.

    Warning No formatter is installed for the format ipb
  • veera_venkatesh178
    edited April 18, 2019 #3

    Thank you for the quick Reply Jfranken, As you said Write HTML and JavaScript code in the Text element to generate the tabs , I tried a code to Create a button you can see that below`
    GridHandle grid = designFactory.newGridItem("grid", 1, 1);

     CellHandle cell1 =  (CellHandle) ( (RowHandle) grid.getRows().get(0) ).getCells().get(0);
    
      TextItemHandle   button =  designFactory.newTextItem("name");
    
      button.setContentType(DesignChoiceConstants.TEXT_CONTENT_TYPE_HTML);
    
       button.setContent("<button type=\"button\"  onclick=\"myFunction()\">Click Me!</button>");
    
      cell1.getContent().add(button);
    
    TableHandle table =  designFactory.newTableItem("table1", 2, 1, 1, 0); 
    
      RowHandle gridTableHeader = (RowHandle) table.getHeader().get(0);
    
     populateTableData(gridTableHeader);// all  the data for the Table will be populated in this method 
    
    table.setProperty(StyleHandle.DISPLAY_PROP, "none"); // table is hidden
    
     cell1.getContent().add(table);
    `
    

    but now i don't know how to give Javascript for this button which will show the table .Implementation is written in the myFunction() . can you please help in this.
    Thanks and Regards ,
    Venkatesh

  • Hi Venkatesh,

    I do not have an example that uses JavaScript in the engine code. I created the attached report in the BIRT Report Designer. It at least gives you a working example of a report that simulates tabs.

    There are 3 Text elements on the report (show/hide code, button 1, button 2). They could be combined into one element if you prefer. The tables were given bookmark properties. The bookmarks get rendered as id's for the table elements in the generated web page making it easy to reference the tables in the script.

    If I find a code example, I will post it. I hope the report is helpful.

    Warning No formatter is installed for the format ipb
  • veera_venkatesh178
    edited April 19, 2019 #5

    Thank you so much jfraken i really appreciate your response and suggestion. Your Suggestion to use table bookmark and combine all the three text Elements worked for me :)
    if you don't mind i have one more problem ,I am writing all the javascript using the text elements . I mean repeating same line of javascript code for every element(button). To overcome that I am creating one .js(report.js) Script for the entire report and adding the .js file to the report (.rptdesign) using resource in the Property Tab .I tried the below code
    `

    TextItemHandle   script =  designFactory.newTextItem("name");
    script .setContentType(DesignChoiceConstants.TEXT_CONTENT_TYPE_HTML);
    script.setContent("<script src=\ "report.js\"><Script>");
    

    `
    But the javascript is not working. can you please tell me where i went wrong .once again thanks for the previous reply :)

  • Warning No formatter is installed for the format ipb
  • veera_venkatesh178
    edited April 19, 2019 #7

    Jfranken , I followed the link that you provided In that second Comment by jason weatherby, Mention like
    <script type="text/javascript" src="http://localhost:8080/2.5.2/externalmyjsfile.js"></script>
    I tried this one but no use . I didn't understand what that /2.5.2 means

  • jfranken
    edited April 19, 2019 #8

    I have experience referencing external JavaScript files in reports run in iServer and iHub, but as I mentioned previously, I have not tried to do this in engine code. My guess is that it should function similarly to other web pages. If that is the case, then there is good information on referencing external files here: https://w3schools.com/js/js_whereto.asp There are several sections on the page. Check out the last section titled, "External References".

    Warning No formatter is installed for the format ipb
  • jfranken
    edited April 22, 2019 #9

    I was reading this thread again and I want to clarify one thing I wrote. When discussing how to reference the external JavaScript file, I mentioned the engine. The JavaScript code that is being added to the Text element gets run in the browser (client code), not on the server. You need to add it to the engine code that generates the report, but it doesn't actually run until the report is loaded in the browser. That is why I said the file reference should work the same as a standard web page- it's being loaded into the browser.

    Warning No formatter is installed for the format ipb