Hi Viet,
Follow this steps to add pagination. I am listing those areas that added/modified for this, for the rest look at corresponding files attached. SearchText could be handled in a way during Add/Remove so user comes back to the last search criteria hi left. If this works than user will be always focused into set of data, rather going back to the whole set and researching again.
Add these properties to GetDataElementListAction.java.
private String searchText ="";
public String getSearchText() {
return searchText;
}
public void setSearchText(String searchText) {
this.searchText
= searchText;
}
private int pageSize = 10;
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
private int currentPage = 0;
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
Change //dataElements = new ArrayList(
dataElementService.getAllDataElements() ); to
dataElements = new ArrayList( dataElementService.getDataElements(currentPage, pageSize, searchText) );
Create dataElementService.getDataElements(currentPage, pageSize, searchText) as such:
// helper method for query based search, needed to add %% to search string and test if it is not null
private String getSearchPattern(String criteria) {
if (StringUtils.hasText(criteria)) {
return "%" + criteria.toLowerCase().replace('*', '%') + "%";
} else {
return "%%";
}
}
@SuppressWarnings("unchecked")
@Override
public Collection getDataElements(int currentPage,
int pageSize, String searchText) {
String pattern = getSearchPattern(searchText);
Session session = sessionFactory.getCurrentSession();
Criteria criteria = session.createCriteria( DataElement.class );
criteria.add(Restrictions.sqlRestriction("lower({alias}.name) like lower(?)", pattern, Hibernate.STRING)); //this is needed only if you want search functionality
return criteria.setMaxResults(pageSize).setFirstResult(currentPage * pageSize).list();
}
Add these to dataelement.vm
for search at the top:
#parse( "/dhis-web-maintenance-datadictionary/search.vm" )
for pagination (prev/next) at the ned of table:
pagination.7z (5.29 KB)
···
From: Viet Nguyen phamquocviet@gmail.com
To: Murodullo Latifov murodlatifov@yahoo.com
Cc: Hieu Dang Duy hieu.hispvietnam@gmail.com; Dhis2 dhis2-devs@lists.launchpad.net
Sent: Mon, March 8, 2010 3:10:45 PM
Subject: Re: [Dhis2-devs] Translation function - Stay at page after modified some thing
On Mon, Mar 8, 2010 at 3:04 PM, Murodullo Latifov murodlatifov@yahoo.com wrote:
Hi all,
In this connection I also implemented server side pagination for dhis. This could be used in Dataelement listing, patient records, etc. There is also search facility working with pagination to narrow down scope. It may need speed comparison with existing single listings and other pros and cons.
regards,
murod
Hi,
I’m also planing to implement a paging util for patient module.
May I see your code 