`

how to implement sorting by clicking on header in Search Container

 
阅读更多

参考: http://itsliferay.blogspot.com/2011/07/orderable-search-container.html

http://itsliferay.blogspot.in/2014/04/sort-search-container-result.html

 

1 在jsp页面加上 orderable 和 orderableProperty

<liferay-ui:search-container-column-text
				name="updateDate"
				value="${updateDate}"
				orderable="<%= true %>"
				orderableProperty="updateDate"
			/>

 2. 自定义排序的类

package com.labimo.lesson.portlet.util;

import com.labimo.lesson.model.Lesson;
import com.liferay.portal.kernel.util.OrderByComparator;
import com.liferay.portal.kernel.util.OrderByComparatorFactory;

public class LessonNameComparator extends OrderByComparator {
	private static final long serialVersionUID = -4030654580941693641L;
	public static String ORDER_COl = "name";
	public static String ORDER_BY_ASC = "name ASC";
	 
	 public static String ORDER_BY_DESC = "name DESC";
	 
	 
	  public LessonNameComparator() 
	  {
	   this(false);
	  }
	 
	  public LessonNameComparator(boolean asc) {
	   _asc = asc;
	  }
	 
	 
	 
	 public int compare(Object obj1, Object obj2) {
	   
	   Lesson instance1 = (Lesson) obj1;
	   Lesson instance2 = (Lesson) obj2;
	   
	   int value = instance1.getName().toLowerCase().compareTo(instance2.getName().toLowerCase());
	 
	   if(_asc) 
	   {
	    return value;
	   } else 
	   {
	    return -value;
	   }
	    
	 }
	 
	 
	 public String getOrderBy() {
	  
	  if (_asc) {
	   return ORDER_BY_ASC;
	  } 
	  else {
	   return ORDER_BY_DESC;
	  }
	  }
	 
	 private boolean _asc;
	 
	


}

 

 在MVCPortlet 的自实现类里面加上下面代码

  // sort
				  String orderByCol = ParamUtil.getString(renderRequest, "orderByCol");
			      String orderByType = ParamUtil.getString(renderRequest, "orderByType");
			      String curValue = ParamUtil.getString(renderRequest, "curr");
			      if(Validator.isNull(orderByCol)){
			    	  orderByCol = LessonNameComparator.ORDER_COl;
			      }
			      
			      if(Validator.isNull(orderByType)){
			    	  orderByType = "asc";
			      }
			      
			      OrderByComparator orderByComparator = null ;
			      if(LessonNameComparator.ORDER_COl.equals(orderByCol)){
			    	  if(orderByType!=null && orderByType.equalsIgnoreCase("desc")){
			    		  orderByComparator = new LessonNameComparator(false);
			        }else{
			        	orderByComparator = new LessonNameComparator(true);
			        }
			      
			      }


// 设置传进来的值
  searchContainer.setOrderByCol(orderByCol);
		        searchContainer.setOrderByType(orderByType);

 

 

分享到:
评论

相关推荐

    This application shows you how to implement professional loo

    This application shows you how to implement professional looking scrolling credits. There are two different demos: top to bottom and left to right. You can click on the credited individual to send him...

    SAP 实施方法论(Run SAP Methodology How to Implement End-to-End Solution Operations )

    SAP 方法论 Run SAP Methodology How to Implement End-to-End Solution Operations

    HOW TO IMPLEMENT EVENTS IN TABLE MAINTENANCE

    ### 如何在表维护中实现事件 本文将详细介绍如何在表维护中实现事件,并通过一个具体案例来展示这一过程。该方法特别适用于在创建新条目时进行多种验证和检查。 #### 场景设定 假设我们需要更新一张自定义表...

    How to Implement ObjectOriented Programming Principles in MATLAB

    在MATLAB中实现面向对象编程(Object-Oriented Programming,OOP)原理是提升代码组织性和可维护性的重要方法。MATLAB虽然最初设计为一种数值计算工具,但随着时间的发展,它逐渐增加了对OOP的支持。...

    Swift.Data.Structure.and.Algorithms

    AVL trees, and Trie trees, and take a look at several substring search algorithms Get to know about the data structures used in graphs and how to implement graphs such as depth-first search, breadth-...

    Swift Data Structure and Algorithms [2016]

    Get to know about the data structures used in graphs and how to implement graphs such as depth-first search, breadth-first search, directed graphs, spanning tree, and shortest path Explore algorithm ...

    Solr in Action(Manning,2014)

    Solr in Action teaches you to implement scalable search using Apache Solr. This easy-to-read guide balances conceptual discussions with practical examples to show you how to implement all of Solr's ...

    Learning.JavaScript.Data.Structures.and.Algorithms.1783554878

    we will round off by learning how to differentiate between various searching and sorting algorithms such as sequential search, binary search, quick sort, bubble sort, and so on, and how to implement ...

    This application demonstrates how to implement a splitter ba

    【标题】: "Visual Basic项目中的分割条实现示例应用" 【描述】: 在软件开发中,分割条(Splitter Bar)是一种常见的用户界面元素,它允许用户动态调整两个或多个区域的大小,以优化视图空间。...

    Machine Learning: Step-by-Step Guide To Implement Algorithms with Python

    Machine Learning: Step-by-Step Guide To Implement Machine Learning Algorithms with Python By 作者: Rudolph Russell ISBN-10 书号: 1719528403 ISBN-13 书号: 9781719528405 出版日期: 2018-05-22 pages ...

    How to implement SCP-ECG, Part II

    ### 如何实施SCP-ECG(第二部分) #### 引言 随着信息技术的进步与医疗行业的融合不断加深,电生理信号的记录与传输变得尤为重要。在众多应用中,心电图(ECG)作为早期检测心脏疾病的一项非侵入性检查手段,在西方...

    Hands On Transfer Learning with Py Implement Advanced DL and NN Models Using T,K

    By the end of this book, you will be able to implement both DL and transfer learning principles in your own systems. What you will learn • Set up your own DL environment with graphics processing ...

    Docker for Serverless Applications

    Chapter 8, Putting Them All Together, explains how to implement a heterogeneous FaaS system combining all three FaaS platforms running seamlessly together on a robust product-grade Swarm cluster....

    iphone FastEnumeration

    Keep in mind that while this sample demonstrates how to implement the NSFastEnumeration protocol, most developers will be better served by using one of the built in Foundation container classes, such ...

    Practical Convolutional Neural Networks Implement advanced d l models using Py

    By the end of this book, you should be ready to implement advanced, effective and efficient CNN models at your professional project or personal initiatives by working on complex image and video ...

    Elasticsearch in Action(Manning,2015)

    Elasticsearch in Action teaches you how to build scalable search applications using Elasticsearch. You'll ramp up fast, with an informative overview and an engaging introductory example. Within the ...

    spring.microservices.in.action

    You’ll take the services you’ve built in the book and deploy them to Amazon Elastic Container Service (ECS). We’ll also discuss how to automate the build and deployment of your microservices using...

    C++ Data Structures and Algorithms

    By the end of the book, you’ll know how to build components that are easy to understand, debug, and use in different applications. Contents 1: LEARNING DATA STRUCTURES AND ALGORITHMS IN C++ 2: ...

    Spring Microservices

    By the end of the book, you'll will gain more clarity on how to implement microservices using Spring Framework and use them in Internet-scale deployments through real-world examples.

Global site tag (gtag.js) - Google Analytics