动态更改搜索容器结果liferay

时间:2015-06-26 09:22:27

标签: ajax liferay liferay-6

我认为我的问题类似于How to search inside of a search container in liferay

因此页面onload有一个设置

的jsp变量
<liferay-ui:search-container-results>
    <%                  
    results = ListUtil.subList(myList, searchContainer.getStart(), searchContainer.getEnd());
    total = myList.size();
    pageContext.setAttribute("results", results);
    pageContext.setAttribute("total", total);
    %>
</liferay-ui:search-container-results>

有没有办法通过ajax动态更改myList? 在后端,我将过滤它并返回一个json对象来替换myList变量。

非常感谢有关如何替换myList变量并因此刷新searchContainer表的帮助

1 个答案:

答案 0 :(得分:1)

Even though the questions seem related, you want to do something different than him.

So to answer your question, the implementation your are thinking of can not be done. Reason:

The myList variable is a variable which exists server side. Your JavaScript code runs on the client side. You have no way of manipulate the content of a java variable with JavaScript.

What can be done is the following:

After you have retrieved your JSON response, you remove the HTML for the result rows in the search container and replace it with HTML which you generate in your JavaScript. This can be a little tricky, because you want to replicate exactly the HTML that the liferay-ui:search-container-results tag produces, because otherwise your styling will be broken.

There is one other way than this. Get all search results and display them and do the rest via JavaScript (pagination, search in the table, etc.) For example you could use this: https://www.datatables.net/

or

https://mottie.github.io/tablesorter/docs/example-pager-filtered.html

Be warned, this can get a little bit slow if you reach a critical point of entries displayed ;)