2

I have a page will show a table of data(from database) on start and I am creating multiple fields for searching/filtering purpose.

My controller:

@RequestMapping(value = "/country", method = RequestMethod.GET)
public ModelAndView getCountryList(Model model) {
    List<Country> countryList = countryService.getCountryList();
    model.addAttribute("dateTime", todayDate());
    model.addAttribute("pageTitle", "<a href=\"/pgwrefund\" />COUNTRY</a>");
    return new ModelAndView("country", "countryList", countryList);
}

@RequestMapping(value="/filterCountry")
public ModelAndView getFilteredCountryList(@RequestParam String countrycode,@RequestParam String countryname,Model model){
    List<Country> filteredCountryList = countryService.getFilteredCountryList(countrycode, countryname);
    model.addAttribute("dateTime", todayDate());
    model.addAttribute("pageTitle", "<a href=\"/pgwrefund\" />COUNTRY</a>");
    System.out.println("List country:"+filteredCountryList.size() +"\nValue:"+ filteredCountryList);
    return new ModelAndView("countrytemplate","filteredCountryList",filteredCountryList);
}

My View

 <tbody>
 <c:forEach var="country" items="${countryList}" varStatus="loopStatus">   
 <tr class="tbodydata ${loopStatus.index % 2 == 0 ? 'even' : 'odd'}">  
             <td>${country.countryCode}</td>  
             <td>${country.countryName}</td>  
             <td>&nbsp;</td>  
             <td>&nbsp;</td>  
             <td>&nbsp;</td>  
 </tr>  
 </c:forEach>  
 </tbody>

My filtered table view:

<c:forEach var="country" items="${filteredCountryList}" varStatus="loopStatus">  
        <tr class="tbodydata ${loopStatus.index % 2 == 0 ? 'even' : 'odd'}">  
            <td class="firsttd">${country.countryCode}</td>  
            <td class="secondtd">${country.countryName}</td>  
            <td>&nbsp;</td>  
            <td>&nbsp;</td>  
            <td>&nbsp;</td>  
        </tr>  
</c:forEach>

So now, What I have done here is, first the i enter values to all the field and filter. The view pass the values to controller and it will filter using a query and return back to the view BUT with another table(foreach). Basically, I am replacing the filtered data with the original data. Then problems came up, most of the functions wont work including update and delete. My goal is, my country page able to filter the table data and stay at the same page. Any help will be appreciated.

4
  • Maybe using something like Datatables would make your life easier, see this question Commented Nov 7, 2014 at 6:58
  • Thanks for the suggestion but I wonder if datatables has multiple filter instead of a single one? Commented Nov 7, 2014 at 7:01
  • see datatables.net for sample and docs Commented Nov 7, 2014 at 7:02
  • thank you! you saved tons of my time...actually I did checkout this plugin previously but I didnt see it actually can be customize based on my needs. Commented Nov 7, 2014 at 9:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.