Extjs 网格分页与 Ajax 调用不起作用

标签 extjs extjs4

我能够使用 servlet 从数据库中检索所有记录,但无法对其执行分页。所有记录都显示在网格上,分页工具栏显示为 54 条记录中的 1 条,但实际上显示的是第一页、第二页等的所有记录......

我做了一些研究,一些用户提到了在服务器端使用启动和限制参数,但到目前为止我没有在任何网站上找到相同的线索/示例。如果没有其他且唯一的方法来解决此问题以使用启动和限制参数更改服务器端代码,那么请为我提供有关 java servlet 的示例代码。

还有一点要谈的是,oracle 11g 中没有启动和限制参数(忽略 12c),那么我该如何解决这个问题?

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
                            }
                        ]
                    });
});

这是我的服务器端代码(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();
        }
    }

最佳答案

Oracle有起始和限制,但以不同的名称给出 rownum 和限制

我正在修改您的查询..假设您正在开始并限制从 ext js 到您的servlt

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

假设你的 start =3 并且 limit 是 10

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

关于Extjs 网格分页与 Ajax 调用不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27544667/

相关文章:

json - 如何在 Sencha Touch 2 中使用 Sqlite

javascript - Extjs:如何获取表单的值

javascript - Date.js getWeek() 在实现 Extjs 后停止工作

javascript - sencha touch2 中的加载掩码

ExtJS 4 : How can I configure a store to load models for a specific set of IDs?

extjs 4.1.1 - 本地数据网格中的分页

java - 我可以使用 extjs 将字段值作为数组提交吗?

javascript - 扩展后EXTJS Combobox不按valueField选择

extjs - 如何将 JSON 绑定(bind)到 EXTJS 网格

spring-mvc - Spring mvc 3.2 和 extjs 4.1.3 : do I have to define mvc:resources mapping for al requestMapping path?