Friday, 5 June 2015

Sorting Column in Search Container


  • Write orderable and orderableProperty for column like below


<liferay-ui:search-container-column-text name="Start Date" property="startDate" orderable="true" orderableProperty="startDate"/>


  •  Write render Method in controller class
@Override
public void render(RenderRequest request, RenderResponse response)
throws IOException, PortletException {
//System.out.println("hello1");
setSortParams(request);
super.render(request, response);
}

private void setSortParams(RenderRequest request) {
String jspPage = ParamUtil.getString(request, "jspPage");
//System.out.println("hello"+jspPage);
if (jspPage.equalsIgnoreCase(ProjectConstants.PAGE_PROJECT)) {
String orderByCol = ParamUtil.getString(request, "orderByCol",
"projectId");
request.setAttribute("orderByCol", orderByCol);
String orderByType = ParamUtil.getString(request, "orderByType",
"asc");
request.setAttribute("orderByType", orderByType);
//System.out.println("hello"+orderByCol+"aa"+orderByType);
}
}
  • In JSP Page
List<Projects> projects = ProjectsLocalServiceUtil.getProjectses(0, ProjectsLocalServiceUtil.getProjectsesCount());

String orderByCol = (String) request.getAttribute("orderByCol"); 
String orderByType = (String) request.getAttribute("orderByType"); 
BeanComparator comp = new BeanComparator(orderByCol); 
List<Projects> projectsResults = ListUtil.copy(projects);

Collections.sort(projectsResults, comp); 
//System.out.print("column:"+orderByCol);
//System.out.print("type:"+orderByType);
if (orderByType.equalsIgnoreCase("desc")) {
Collections.reverse(projectsResults); 
}

  • At Last add this attributes
<liferay-ui:search-container orderByCol="<%= orderByCol %>" orderByType="<%= orderByType %>" >
</liferay-ui:search-container>

No comments:

Post a Comment