Back to forum

How to get report table HTML content?

Answered

Hi guys,
The exportTo (‘html’, options) function generates a table in html and saves it to a file for download. Is there any function that just returns that html content in the code (without necessarily forcing the download)? For example:

let htmlTable = generateTableHtml(options);

9 answers

WebDataRocks Team WebDataRocks November 4, 2019

Hello, Gleyton,
 
Thank you for your question.
 
You can return the desired HTML content using the following construction:

function htmlToValue() {
webdatarocks.exportTo("html", null, res => { console.log(res) });
}

 
Find out an example by following the link: https://codepen.io/webdatarocks/pen/JjjpOyb.
 
For now, it’s impossible to call the exportTo method without downloading the file. We recommend you checking on Flexmonster which is a premium pivot table component developed by the same team. The exportTo method without necessarily forcing the download is available in Flexmonster: https://www.flexmonster.com/api/exportto/.
 
Kind regards,
WebDataRocks Team

Cihan June 5, 2020

Hello,
I have this problem. I just want the HTML content, but the exportTo method downloads as an html file.

Gleyton June 8, 2020

Unfortunately, still it’s impossible to call the exportTo method without downloading the file.

Hugo Martinez June 10, 2020

Hi,
 
It is possible to get the HTML content by exporting the report to a server. This way it won’t be downloaded as an HTML file. 
For example, by setting the destinationType export option to "server" and specifying the url property, the report will be sent as a POST parameter to the specified URL and the HTML content will be available in the callback:
 

webdatarocks.exportTo(
"html",
{
destinationType: "server",
url: "URL to server script saving the file"
},
res => {
console.log(res.data); //the HTML content
}
);

 
Further details can be found in this guide: https://www.webdatarocks.com/doc/exportto/ 
 
Hope this helps. 

Gleyton June 10, 2020

The main objective in obtaining the html in our case is to use the default browser print with this content. The standard print of webdatarocks when it has many columns is difficult to read. Take the test: at https://www.webdatarocks.com/demos/javascript-pivot-table-demo/ check the option flat form and add all columns. Now click on “export-> print”. Compare the result with the printing of the exported html file in the option “export-> html” via browser. This will, in my opinion, look much better.

Cihan June 10, 2020

Hi, first of all my question answering for thank you.
I understood what u said, but I use Angular 7 and unfortunately I don’t use ssr. What other solution can I come up with?
 
Thank u for all answers,
good workings ✋

Hugo Martinez July 14, 2020

Hello Cihan,
 
Actually, SSR (server-side rendering) is not required, if I understood you correctly.
Exporting to the server is just a workaround to prevent downloading the file and getting its content to JS callback. Then, you can trigger printing html using some code, for example: https://stackoverflow.com/questions/2255291/print-the-contents-of-a-div
 
Hope this helps. 

Cihan July 14, 2020

Hi Hugo,
What will I send as the element sent to the method in the source you sent?
 
Thanks.

Hugo Martinez August 7, 2020

Hello Cihan,
 
I mean you can send res.data (result of exportTo()):

mywindow.document.write(res.data); // instead of `document.getElementById(elem).innerHTML`

Hugo

Move up