volosoft / jtable

A JQuery plugin to create AJAX based CRUD tables.
http://www.jtable.org
1.1k stars 506 forks source link

Paging & sorting JSP #869

Open ghost opened 11 years ago

ghost commented 11 years ago

Hi, I wanna organize my jTable by paging and sorting it. So, I am working with JSP & servlets. I've created my jTable, but I don't know how to change my controller to paginate my jTable. Here is the part of my code that I have to change in my controller:

CityDAO citydao = new CityDAO();

     if(request.getParameter("action")!=null){
        List<City> cities = new ArrayList<City>();

    String action=(String)request.getParameter("action");
       Gson gson = new Gson();
       response.setContentType("application/json");

       if(action.equals("list")){
        try{  
            //Fetch Data from User Table
            cities=CityDAO.selectAll();   
            //Convert Java Object to Json  
            JsonElement element = gson.toJsonTree(cities, new TypeToken<List<City>>() {}.getType());
            JsonArray jsonArray = element.getAsJsonArray();
            String listData=jsonArray.toString();    
            //Return Json in the format required by jTable plugin
            listData="{\"Result\":\"OK\",\"Records\":"+listData+"}";   
            response.getWriter().print(listData);
            }catch(Exception ex){
             String error="{\"Result\":\"ERROR\",\"Message\":"+ex.getMessage()+"}";
             response.getWriter().print(error);
             ex.printStackTrace();
            }    
           }

Can someone help me, please ?

hikalkan commented 11 years ago

I've no experience with Java and JSP but maybe you can find some documentation here: http://jtable.org/Home/Documents and http://www.programming-free.com/search/label/jTable