zoukankan      html  css  js  c++  java
  • 【原】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( { 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', 250 }, { text: 'Contact Name', datafield: 'ContactName', 200 }, { text: 'Contact Title', datafield: 'ContactTitle', 200 }, { text: 'Address', datafield: 'Address', 180 }, { text: 'City', datafield: 'City', 100 }, { text: 'Country', datafield: 'Country', 140 } ] }); }); </script> </head> <body class='default'> <div id="jqxgrid"></div> </body> </html>

    Java后台

    获取grid发送的pagesize,pagenum

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

  • 相关阅读:
    QStringLiteral(源代码里有一个通过构造函数产生的从const char*到QString的隐式转换,QStringLiteral字符串可以放在代码的任何地方,编译期直接生成utf16字符串,速度很快,体积变大)
    utf8格式源代码中的字符串,默认都会当作char来处理,除非用L""符号来修饰
    Qt Installer Framework的学习
    发布Qt Quick桌面应用程序的方法
    先对数组排序,在进行折半查找(C++)
    7个高效习惯
    人活着是靠精神(几个例子都是我自己发现的)
    VC++对象布局的奥秘:虚函数、多继承、虚拟继承
    delphi数字签名验证及能够获取数字签名文件信息(利用wintrust.dll的导出函数,翻译一下)
    算法系列之二十:计算中国农历(二)
  • 原文地址:https://www.cnblogs.com/superjt/p/4441005.html
Copyright © 2011-2022 走看看