Download full content of search-container as excelDownload full content of search-container as excelhttps://liferay.dev/en/c/message_boards/find_thread?p_l_id=119785333&threadId=1213946132024-03-28T09:56:47Z2024-03-28T09:56:47ZDownload full content of search-container as excelClaudiu Teodorescuhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1213946122022-04-07T12:01:09Z2022-04-07T11:59:31Z<p> </p>
<p>Hi all,</p>
<p>I have a search container to retrieve all user subscriptions.
Everithing is working fine but now I need to create a functionality to
download all the results but I don't find a solution. </p>
<p>
<img alt="" src="/documents/14/0/Capture+%2810%29.png/0a704307-abbd-8595-908a-f4a017d21bb1?t=1649332858394&imagePreview=1" /></p>
<p>I was tring to use javascript to do that like:</p>
<pre>
<code class="language-html"><aui:script>
var tableToExcel = (function() {
var id = document.querySelector("table").setAttribute("id", "assetPublisherTable");
var uri = 'data:application/vnd.ms-excel;base64,'
, template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
, base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) }
, format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) }
return function(table, name) {
if (!table.nodeType) table = document.getElementById(table)
var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}
window.location.href = uri + base64(format(template, ctx))
}
})()
</aui:script></code></pre>
<p>and the Export to Excel button:</p>
<pre>
<code class="language-html"><aui:button-row>
<aui:button onclick="tableToExcel('assetPublisherTable', 'Asset Publisher Subscriptions')" value="Export to Excel"></aui:button>
</aui:button-row></code></pre>
<p>But the issue is that it is downloading only the content from the
current page of the table. </p>
<p> This is because in the java code I do:</p>
<pre>
<code class="language-java">/**
* Gets search container.
*
* @return search container.
*/
public SearchContainer getSearchContainer() {
if (searchContainer != null) {
return searchContainer;
}
searchContainer = new AssetPublisherSubscriptionSearch(renderRequest, getPortletUrl());
DynamicQuery subscriptionCountQuery = getSearchQuery();
long allCount = SubscriptionLocalServiceUtil.dynamicQueryCount(subscriptionCountQuery);
searchContainer.setTotal((int) allCount);
DynamicQuery subscriptionQuery = getSearchQuery();
subscriptionQuery.setLimit(searchContainer.getStart(), searchContainer.getEnd());
List<UserSubscription> items = SubscriptionLocalServiceUtil
.dynamicQuery(subscriptionQuery)
.stream()
.map(this::getUserSubscription)
.collect(Collectors.toList());
if (items == null) {
items = new ArrayList<>();
}
searchContainer.setResults(items);
return searchContainer;
}</code></pre>
<p>I have this
line: <strong>subscriptionQuery.setLimit(searchContainer.getStart(),
searchContainer.getEnd());</strong> which returns the results that
are between start and end of searchContainer, which I assume are
related to the page that is selected.</p>
<p>Any ideea is welcome.</p>
<p>Thank you in advance.</p>
<p> </p>
<p> </