To sort liferay search container result follow below steps.
1) Create liferay search container in your JSP.
2) Create search container in your controller and set result in search container object.
3) Get sorted results using dynamic query.
1) Create liferay search container in your JSP.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<liferay-ui:search-container hover="false" searchContainer="${mySearchContainer}"> | |
<liferay-ui:search-container-results | |
results="${mySearchContainer.results}" | |
total="${mySearchContainer.total}"/> | |
<liferay-ui:search-container-row | |
className="com.liferay.portlet.model.MyCustomBean" | |
keyProperty="Id" modelVar="myObj"> | |
<liferay-ui:search-container-column-text name="no" property="arcNo" cssClass="width10pt"/> | |
<liferay-ui:search-container-column-text name="item.name" property="itemName" orderableProperty="itemName" orderable="true" /> | |
<liferay-ui:search-container-column-text name="req.status" property="status" orderableProperty="status" orderable="true" cssClass="width10pt"/> | |
<liferay-ui:search-container-column-text name="delivery.type" property="deliveryType" orderableProperty="deliveryType" orderable="true" cssClass="width15pt"/> | |
</liferay-ui:search-container-row> | |
<liferay-ui:search-iterator /> | |
</liferay-ui:search-container> |
2) Create search container in your controller and set result in search container object.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY); | |
String orderByCol = ParamUtil.getString(renderRequest, "orderByCol"); | |
String orderByType = ParamUtil.getString(renderRequest, "orderByType"); | |
String curValue = ParamUtil.getString(renderRequest, "curr"); | |
SearchContainer<MyCustomBean> searchContainer = null; | |
//Create Portlet URL and set required param for pagination | |
PortletURL portletURL = PortletURLFactoryUtil.create(portletRequest, PORTLET_ID, themeDisplay.getPlid(), PortletRequest.RENDER_PHASE); | |
searchContainer = new SearchContainer<myCustomBean>(renderRequest, null, null, CUR_CONTENT, DELTA, portletURL, null,StringPool.BLANK); | |
searchContainer.setEmptyResultsMessage(LanguageUtil.get(themeDisplay.getLocale(), "empty-result-message")); | |
searchContainer.setIteratorURL(portletURL); | |
searchContainer.setOrderByCol(orderByCol); | |
searchContainer.setOrderByType(orderByType); | |
searchContainer.setResults(getSortedList(int start, int end, long companyId, String orderByType, String orderByColumn)); | |
searchContainer.setTotal(MyLocalServiceUtil.getCustomBeanCount()); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static List<MyCustomBean> getSortedList(int start, int end, long companyId, String orderByType, String orderByColumn) | |
{ | |
List<MyCustomBean> myList = new ArrayList<MyCustomBean>(); | |
DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(MyCustomBean.class); | |
dynamicQuery.add(PropertyFactoryUtil.forName("companyId").eq(companyId)); | |
dynamicQuery.setLimit(start, end); | |
if (orderByType.equalsIgnoreCase("asc")) | |
{ | |
dynamicQuery.addOrder(OrderFactoryUtil.asc(orderByColumn)); | |
} else | |
{ | |
dynamicQuery.addOrder(OrderFactoryUtil.desc(orderByColumn)); | |
} | |
try | |
{ | |
myList= MyLocalServiceUtil.dynamicQuery(dynamicQuery); | |
} catch (SystemException e) | |
{ | |
LOGGER.error(e.getMessage()); | |
} | |
return myList; | |
} | |
hi, nce work..can u sahre the code once pls.
ReplyDeleteI don't have sample portlet for this . But you can use the code snippet i posted in this blog.
ReplyDeleteI am having 4 drop down i want to change the search result according to the drop down values ,Like if i want to values from particular state than it should show the complete state results .
ReplyDeleteI used DynamicQueryFactoryUtil and criterion for this .Please give me any suggestion for this ..
What problem you are facing ? Read the user selected inputs and pass the same in dynamic query to filter records.
Delete