【原】Jqxgrid在Java服务器端分页

研究这个后台分页一天多,特此写个文章记录备忘

jsp页面中有两个需要注意的地方:一个是source中beforeprocessing,另一个是rendergridrows中数据的获取。

说明:grid会向服务器发送以下参数

the Grid sends the following data to the server:
sortdatafield - the sort column‘s datafield.
sortorder - the sort order - ‘asc‘, ‘desc‘ or ‘‘
pagenum - the current page‘s number when the paging feature is enabled.
pagesize - the page‘s size which represents the number of rows displayed in the view.
groupscount - the number of groups in the Grid
group - the group‘s name. The group‘s name for the first group is ‘group0‘, for the second group is ‘group1‘ and so on.
filterscount - the number of filters applied to the Grid
filtervalue - the filter‘s value. The filtervalue name for the first filter is "filtervalue0", for the second filter is "filtervalue1" and so on.
filtercondition - the filter‘s condition. The condition can be any of these: "CONTAINS", "DOES_NOT_CONTAIN", "EQUAL", "EQUAL_CASE_SENSITIVE", NOT_EQUAL","GREATER_THAN", "GREATER_THAN_OR_EQUAL", "LESS_THAN", "LESS_THAN_OR_EQUAL", "STARTS_WITH", "STARTS_WITH_CASE_SENSITIVE", "ENDS_WITH", "ENDS_WITH_CASE_SENSITIVE", "NULL", "NOT_NULL", "EMPTY", "NOT_EMPTY"
filterdatafield - the filter column‘s datafield
filteroperator - the filter‘s operator - 0 for "AND" and 1 for "OR"

JSP页面:

<!DOCTYPE html>
<html lang="en">
<head>
    <link rel="stylesheet" href="../jqwidgets/styles/jqx.base.css" type="text/css" />
    <link rel="stylesheet" href="../jqwidgets/styles/jqx.classic.css" type="text/css" />
    <script type="text/javascript" src="../jquery-1.11.1.min.js"></script>
    <script type="text/javascript" src="../jqwidgets/jqxcore.js"></script>
    <script type="text/javascript" src="../jqwidgets/jqxbuttons.js"></script>
    <script type="text/javascript" src="../jqwidgets/jqxscrollbar.js"></script>
    <script type="text/javascript" src="../jqwidgets/jqxmenu.js"></script>
    <script type="text/javascript" src="../jqwidgets/jqxcheckbox.js"></script>
    <script type="text/javascript" src="../jqwidgets/jqxlistbox.js"></script>
    <script type="text/javascript" src="../jqwidgets/jqxdropdownlist.js"></script>
    <script type="text/javascript" src="../jqwidgets/jqxgrid.js"></script>
    <script type="text/javascript" src="../jqwidgets/jqxgrid.pager.js"></script>
    <script type="text/javascript" src="../jqwidgets/jqxgrid.selection.js"></script>
    <script type="text/javascript" src="../jqwidgets/jqxdata.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            // prepare the data
            var theme = ‘classic‘;
            var source =
            {
                datatype: "json",
                datafields: [
                     { name: ‘CompanyName‘ },
                     { name: ‘ContactName‘ },
                     { name: ‘ContactTitle‘ },
                     { name: ‘Address‘ },
                     { name: ‘City‘ },
                     { name: ‘Country‘ }
                ],
                cache: false,
                url: ‘data.php‘,
                root: ‘Rows‘,
                beforeprocessing: function (data) {            //根据实际做相应的调整不一定是data[0].TotalRows;建议写个debugger;调试            debugger;
                    source.totalrecords = data[0].TotalRows;
                }
            };
            var dataadapter = new $.jqx.dataAdapter(source);
            // initialize jqxGrid
            $("#jqxgrid").jqxGrid(
            {
                width: 600,
                source: dataadapter,
                theme: theme,
                autoheight: true,
                pageable: true,
                virtualmode: true,
                rendergridrows: function (params) {            //这里的返回值需要根绝实际情况作调整。如果params.data获取不到。可以用dataadapter来获取,如dataadapter.recordids[0].*等            debugger;
                    return params.data;
                },
                columns:
                [
                    { text: ‘Company Name‘, datafield: ‘CompanyName‘, width: 250 },
                    { text: ‘Contact Name‘, datafield: ‘ContactName‘, width: 200 },
                    { text: ‘Contact Title‘, datafield: ‘ContactTitle‘, width: 200 },
                    { text: ‘Address‘, datafield: ‘Address‘, width: 180 },
                    { text: ‘City‘, datafield: ‘City‘, width: 100 },
                    { text: ‘Country‘, datafield: ‘Country‘, width: 140 }
                ]
            });
        });
    </script>
</head>
<body class=‘default‘>
    <div id="jqxgrid"></div>
</body>
</html>

Java后台

获取grid发送的pagesize,pagenum

然后获取数据库数据后返回JSON格式数据即可。

时间: 2024-11-03 02:40:08

【原】Jqxgrid在Java服务器端分页的相关文章

bootstrap table 服务器端分页--ashx+ajax

1.准备静态页面 1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 5 <title></title> 6 <meta charset="utf-8" /> 7 <link rel="

java超强分页标签演示

最近在做一个项目,用到了一个分页,于是动手写了个分页标签,先将代码贴出来,供大家交流,写的不好,请见谅!. 以下是java标签类,继承自SimpleTagSupport [java] view plaincopyprint? package com.lynn.oa.tag; import java.io.IOException; import java.util.ArrayList; import java.util.List; import javax.servlet.jsp.JspExcep

JAVA实现分页

JAVA实现分页有三种方式: 1:使用list接口中的Sublist实现分页            效率低 2:直接使用数据库SQL语句实现分页(mysql中用limit关键字,oracle用rownum关键字)   数据库兼容性差 3: hibernate框架实现跨数据库分页  兼容不同数据库 但是复杂查询性能低 使用Hibernate 创建Query对象,查询时设置firstResult和MaxResuit属性

java 关于分页的实现

 关于java实现分页 转自:http://www.cnblogs.com/slliang/archive/2012/08/22/2651053.html 1.分页工具类,封装分页信息 package com.student.util; import java.util.List; import com.student.entity.Person; /** * 封装分页信息 * @author Administrator * * @param <Person> */ public class

JAVA服务器端性能优化----String

String的连接 方法1 使用+= String s = new String(); for (int i = 0; i < 10000; i++){ s+= "a"; } 方法2 使用带缓冲区的StringBuffer StringBuffer s = new StringBuffer(); for (int i = 0; i < 10000; i++){ s.append("a") } 方法1执行时间大概在2000ms左右,方法2却只要10ms左右

java内存分页

List<BofCytProduct> bofCytProductArray=getAllOnProdcuct(); List<BofCytProduct> list = new ArrayList<BofCytProduct>(); for(BofCytProduct bofCytProduct:bofCytProductArray){ if(!ProductCodeConstants.JI_JIN.equals(bofCytProduct.getTypeCode()

java MongoDB分页优化

最近项目在做网站用户数据新访客统计,数据存储在MongoDB中,统计的数据其实也并不是很大,1000W上下,但是公司只配给我4G内存的电脑,让我程序跑起来气喘吁吁...很是疲惫不堪. 最常见的问题莫过于查询MongoDB内存溢出,没办法只能分页查询.这种思想大家可能都会想到,但是如何分页,确实多有门道! 网上用的最多的,也是最常见的分页采用的是skip+limit这种组合方式,这种方式对付小数据倒也可以,但是对付上几百上千万的大数据,却只能望而兴叹... 经过网上各种查找资料,寻师问道的,发现了

java web 分页技术

查询界面,通过姓名和车号进行查询,然后将查询结果提交给servlet: <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.

用DataTables实现服务器端分页

推荐下,H-ui.admin 模版里面使用了DataTables,而且把常用功能都给实现的很完整了,推荐去参考H-ui的模版源码参考! 分享几篇有价值的文章: DataTables 的官网:https://datatables.net Bootstrap插件DataTables实现服务器端分页http://lovelock.coding.me/javascript/bootstrap-plugin-datatables/ PHP+Ajax+Datatables实现分页https://blog.c