Extjs grid instance with Ajax call not working

I can fetch all the records from the database using a servlet, but was unable to paging on the same one. All records are displayed in a grid with a paging toolbar showing 1 out of 5 of 54 records, but it actually displays all records on the first page, on the second page, etc ...

I have done some research and some users have mentioned using launch options and server side constraints and I still haven't found a key / example on the same site. If there is no alternative and the only way to fix it is to change the server side code with launch and constraint parameters, please provide me with a sample Java Servlet code.

One more thing to say about this is there are no start and limit parameters in oracle 11g (don't count 12c), so how can I fix this?

Ext.onReady(function ()
{
var itemsPerPage =5;
var store = Ext.create('Ext.data.Store',{
   storeId: 'resultsetstore',
   autoload: false,
   pageSize:itemsPerPage,
   fields:
           [
                {name: 'firstname', id:'firstname'},
                {name: 'email', id:'email'},
                {name: 'mobileno', id:'mobileno'}
           ],
           proxy:
                   {
                       type:'ajax',
                       enablePaging: true,
                       url:'./RetrieveRecords'
                   },
                   reader:{type:'json',totalProperty: 'total'}
});
store.load();


Ext.create('Ext.grid.Panel',{
    store:store,
    layout: 'border',
    height:300,
    renderTo: Ext.getBody(),
    columns:
            [
                    {
                        header: 'Email',
                        id: 'email',
                        dataIndex: 'email',
                        //autoSizeColumn : true,
                        flex: 1,
                        editor: {
                            xtype: 'textarea'
                        }
                    },
                    {
                        header: 'Action',
                        id: 'action',
                        align: 'center',
                        xtype: 'actioncolumn',
                        autoSizeColumn: true,
                        //flex: 1, 
                        sortable: false,
                        items:
                                [
                                    {
                                        icon: 'images/icons/cancel.png',
                                        tooltip: 'Delete',
                                        handler: function (grid, rowIndex, colIndex)
                                        {
                                            var rec = grid.getStore().getAt(rowIndex);
                                            var email = rec.get('email');
                                            Ext.Ajax.request(
                                                    {
                                                        url: './deleteRecords',
                                                        params: {email: email},
                                                        method: 'GET',
                                                        success: function (response)
                                                        {
                                                            Ext.Msg.alert("successfully deleted" + " " + response.status);
                                                            window.location.reload();
                                                        },
                                                        failure: function (response)
                                                        {
                                                            Ext.Msg.alert("failed" + response.status);
                                                        }
                                                    });
                                        }
                                    }
                                ]
                            }
                        ],
                dockedItems:
                        [
                            {
                                xtype: 'pagingtoolbar',
                                store: store,
                                dock: 'bottom',
                                displayInfo: true
                            }
                        ]
                    });
});

      

Here is my server code (Java Servlet):

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException, Exception 
    {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();

        JSONArray jarray = new JSONArray();
        try
        {
            Connection con = DBConnection.getConnection();
            Statement st = con.createStatement();
            String query = "select EMAIL,MOBILENO,FIRSTNAME from UP_CLOUD_REGISTRATION";
            ResultSet rs = st.executeQuery(query);

            while(rs.next())
            {
                JSONObject json = new JSONObject();
                json.put("email",rs.getString("email"));
                json.put("mobileno", rs.getString("mobileno"));
                json.put("firstname", rs.getString("firstname"));
                jarray.add(json);
            }
            out.println(jarray);
            System.out.println(jarray);
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }

      

+3


source to share


1 answer


Oracle has a start and a limit, but it was given by different names rownum and a limit on

I am changing your request .. suppose you get start and limit from ext js to your servelt

  select EMAIL,MOBILENO,FIRSTNAME from UP_CLOUD_REGISTRATION where rownum>=start and limit by limit(value from ext js)

      



suppose if you got start = 3 and the limit is 10

 select EMAIL,MOBILENO,FIRSTNAME from UP_CLOUD_REGISTRATION where rownum>=3 and limit by 10

      

+2


source







All Articles