Index: src/main/java/it/finki/charitable/controller/DonationPostController.java
===================================================================
--- src/main/java/it/finki/charitable/controller/DonationPostController.java	(revision ee0e2972779503cbac7ff1584f4ff29c30bac548)
+++ src/main/java/it/finki/charitable/controller/DonationPostController.java	(revision 7888b17443c71c7e2c64f2beae81d2a29dc74d25)
@@ -4,5 +4,5 @@
 import it.finki.charitable.services.*;
 import it.finki.charitable.util.FileUploadUtil;
-import org.springframework.data.domain.Page;
+import org.springframework.data.domain.*;
 import org.springframework.format.annotation.DateTimeFormat;
 import org.springframework.security.core.context.SecurityContextHolder;
@@ -15,8 +15,5 @@
 import java.io.IOException;
 import java.time.LocalDate;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Objects;
+import java.util.*;
 import java.util.stream.Collectors;
 
@@ -126,6 +123,61 @@
                         @RequestParam int page,
                         @RequestParam String sort,
-                        @RequestParam(required = false,defaultValue = "") String order) {
-        Page<DonationPost> postList = donationPostService.findPaginated(page,6, sort, order, true);
+                        @RequestParam(required = false, defaultValue = "desc") String order,
+                        @RequestParam(required = false, defaultValue = "all") String groupBy) {
+
+        Sort s = Sort.by(sort);
+        s = order.equals("asc") ? s.ascending() : s.descending();
+        Pageable pageable = PageRequest.of(page - 1, 6, s);
+        Page<DonationPost> postList;
+        postList = donationPostService.findPaginated(page, 6, sort, order, true);
+
+        if (!groupBy.equals("all")) {
+            List<DonationPost> allPosts = donationPostService.findAllByApproved(true);
+
+            if (sort.equals("title")) {
+                if (order.equals("asc")) {
+                    allPosts.sort(Comparator.comparing(DonationPost::getTitle, (s1, s2) -> s1.compareToIgnoreCase(s2)));
+                } else {
+                    allPosts.sort(Comparator.comparing(DonationPost::getTitle, (s1, s2) -> s2.compareToIgnoreCase(s1)));
+                }
+            } else if (sort.equals("dateDue")) {
+                if (order.equals("asc")) {
+                    allPosts.sort(Comparator.comparing(DonationPost::getDateDue));
+                } else {
+                    allPosts.sort(Comparator.comparing(DonationPost::getDateDue).reversed());
+                }
+            } else if (sort.equals("fundsNeeded")) {
+                if (order.equals("asc")) {
+                    allPosts.sort(Comparator.comparing(DonationPost::getFundsNeeded));
+                } else {
+                    allPosts.sort(Comparator.comparing(DonationPost::getFundsNeeded).reversed());
+                }
+            }
+
+            if (groupBy.equals("completed")) {
+                List<DonationPost> completed = allPosts.stream().filter(post -> {
+                    double fundsCollected = post.getFundsCollected().stream().mapToDouble(FundsCollected::getFunds).sum();
+                    return fundsCollected >= post.getFundsNeeded();
+                }).collect(Collectors.toList());
+
+                int start = (int) pageable.getOffset();
+                int end = Math.min((start + pageable.getPageSize()), completed.size());
+                if (start <= end) {
+                    postList = new PageImpl<>(completed.subList(start, end), pageable, completed.size());
+                }
+            } else if (groupBy.equals("expired")) {
+                List<DonationPost> expired = allPosts.stream().filter(post -> {
+                    double fundsCollected = post.getFundsCollected().stream().mapToDouble(FundsCollected::getFunds).sum();
+                    return LocalDate.now().isAfter(post.getDateDue()) && fundsCollected < post.getFundsNeeded();
+                }).collect(Collectors.toList());
+
+                int start = (int) pageable.getOffset();
+                int end = Math.min((start + pageable.getPageSize()), expired.size());
+                if (start <= end) {
+                    postList = new PageImpl<>(expired.subList(start, end), pageable, expired.size());
+                }
+            }
+        }
+
         if (postList.getTotalElements() == 0) {
             model.addAttribute("noPosts", true);
@@ -193,5 +245,5 @@
         DonationPost donationPost = donationPostService.getById(postid);
         ReportPost reportPost = reportPostService.findByDonationPost(donationPost);
-        if(reportPost == null) {
+        if (reportPost == null) {
             reportPost = new ReportPost();
             reportPost.setDonationPost(donationPost);
