Created
December 17, 2011 23:02
-
-
Save rafalrusin/1491712 to your computer and use it in GitHub Desktop.
DataTables JEE
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
private boolean filter(String sSearch, List<Object> list) { | |
if (sSearch.equals("")) { | |
return true; | |
} | |
return list.toString().contains(sSearch); | |
} | |
... | |
List<List<Object>> filteredList = new ArrayList<List<Object>>(); | |
for (int i = 0; i < myList.size(); i++) { | |
if (filter(sSearch, myList.get(i))) { | |
filteredList.add(myList.get(i)); | |
} | |
} | |
Collections.sort(filteredList, new Comparator<List<Object>>() { | |
@Override | |
public int compare(List<Object> o1, List<Object> o2) { | |
if (sSortDir_0) { | |
return o1.get(iSortCol_0).toString().compareTo(o2.get(iSortCol_0).toString()); | |
} else { | |
return o2.get(iSortCol_0).toString().compareTo(o1.get(iSortCol_0).toString()); | |
} | |
} | |
}); | |
List<List<Object>> selectedList = new ArrayList<List<Object>>(); | |
for (int i = iDisplayStart; i < iDisplayStart + iDisplayLength; i++) { | |
if (i < filteredList.size()) { | |
if (filter(sSearch, filteredList.get(i))) { | |
selectedList.add(filteredList.get(i)); | |
} | |
} | |
} |
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
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | |
int iDisplayStart = Integer.parseInt(request.getParameter("iDisplayStart")); | |
int iDisplayLength = Integer.parseInt(request.getParameter("iDisplayLength")); | |
String sSearch = request.getParameter("sSearch"); | |
final int iSortCol_0 = Integer.parseInt(request.getParameter("iSortCol_0")); | |
final boolean sSortDir_0 = request.getParameter("sSortDir_0").equals("asc"); |
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
$(document).ready(function() { | |
$('#example').dataTable( { | |
"bProcessing": true, | |
"bServerSide": true, | |
"bPaginate": true, | |
"sAjaxSource": "datatablesjee" | |
} ); | |
} ); |
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
ObjectMapper mapper = new ObjectMapper(); | |
result.put("iTotalRecords", myList.size()); | |
result.put("iTotalDisplayRecords", filteredList.size()); | |
result.put("aaData", selectedList); | |
mapper.writeValue(response.getOutputStream(), result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment