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<DataElement>(
dataElementService.getAllDataElements() ); to
dataElements = new ArrayList<DataElement>(
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<DataElement> 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:
<div class="nav">
#if($currentPage>0)
#set( $prevPage = $currentPage - 1 )
<a id="prevResultsLink"
href="dataElement.action?searchText=$searchText&pageSize=$pageSize¤tPage=$prevPage">$i18n.getString(
"command.prev")</a>
#end
        
#if($count==$pageSize)
#set( $nextPage = $currentPage + 1 )
<a id="prevResultsLink"
href="dataElement.action?searchText=$searchText&pageSize=$pageSize¤tPage=$nextPage">$i18n.getString(
"command.more")</a>
#end
</div>
________________________________
From: Viet Nguyen <[email protected]>
To: Murodullo Latifov <[email protected]>
Cc: Hieu Dang Duy <[email protected]>; Dhis2
<[email protected]>
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 <[email protected]>
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 :-)
pagination.7z
Description: Binary data
_______________________________________________ Mailing list: https://launchpad.net/~dhis2-devs Post to : [email protected] Unsubscribe : https://launchpad.net/~dhis2-devs More help : https://help.launchpad.net/ListHelp

