Home Web Front-end HTML Tutorial EasyUI ComboGrid Pagination_html/css_WEB-ITnose

EasyUI ComboGrid Pagination_html/css_WEB-ITnose

Jun 24, 2016 am 11:45 AM

1. Usage Scenarios

The drop-down box can easily provide us with the selection function. Through the drop-down box, we can easily select a certain value without manual input. There is a ComboGrid corresponding to it in EasyUI. ComboGrid can be used not only as a drop-down box, but also for searching, displaying data that matches the currently entered characters.
Generally we have two ways to use ComboGrid. One is to obtain the data first, bring it to the page, and then render it when the page is loaded; the other is to request the background service through ajax after the page is loaded, obtain the json data, and then render it. Both methods can be used in general applications and have no other problems. However, when the amount of data is large, neither of these two methods can meet our needs well. For example, when the amount of data reaches tens of thousands or hundreds of thousands, the time to load the page will become significantly longer or even freeze. At this time, we can use the ComboGrid paging method to display the data in paging.

2. Example

The html code is as follows:

  1 <!DOCTYPE html>  2 <html>  3 <head>  4   5 <meta charset="utf-8"/>  6 <title>easyui-combox 分页示例</title>   7     <link rel="stylesheet" type="text/css" href="resource/themes/default/easyui.css">  8     <link rel="stylesheet" type="text/css" href="resource/themes/icon.css">  9     <link rel="stylesheet" type="text/css" href="resource/demo.css"> 10 </head> 11 <body> 12     <div>  13         <span><b class="tool_box_b">选择用户:</b></span> 14         <div> 15             <input id="person" style="width:285px;"/> 16             <input id="personId" type="hidden" name="personId"/> 17             <input type="text" id="txtName" style="display: none;" /> 18               <input type="text" id="txtId" style="display: none;" /> 19         </div> 20     </div>                               21 <script type="text/javascript" src="resource/jquery.min.js"></script> 22 <script type="text/javascript" src="resource/jquery.easyui.min.js"></script> 23 <script type="text/javascript"> 24 $(function () { 25     $('#person').combogrid({ 26         panelWidth: 400, 27         idField: 'id',        //ID字段   28         textField: 'name',    //显示的字段   29         url: "${pageContext.request.contextPath}/controller/persons.action", 30         fitColumns: true, 31         striped: true, 32         editable: true, 33         pagination: true,           //是否分页 34         rownumbers: true,           //序号 35         collapsible: false,         //是否可折叠的 36         fit: true,                  //自动大小 37         method: 'post', 38         columns: [[ 39             { field: 'name', title: '页面名称', width: 80 }, 40             { field: 'id', title: '用户id', width: 80, hidden: true }, 41         ]], 42         keyHandler: { 43             query: function (keyword) {     //【动态搜索】处理 44                 var comgrid = $('#person').combogrid("grid"); 45                 var queryParams = comgrid.datagrid('options').queryParams;  //设置查询参数 46                 queryParams.keyword = keyword; 47                 comgrid.datagrid('options').queryParams = queryParams; 48                 comgrid.datagrid("reload");    //重新加载 49                 $('#person').combogrid("setValue", keyword); 50                 //将查询条件存入隐藏域 51                 $('#txtId').val(keyword); 52             } 53         }, 54         onSelect: function () {              //选中处理 55             var seldata = $('#person').combogrid('grid').datagrid('getSelected'); 56             $('#txtName').val(seldata.name); 57             $('#txtId').val(seldata.id); 58             $('#personId').val(seldata.id); 59             //alert(seldata.id+"--"+seldata.name); 60         } 61     }); 62            63     //取得分页组件对象 64     var pager = $('#person').combogrid('grid').datagrid('getPager'); 65        66     if (pager) { 67         $(pager).pagination({ 68              pageSize: 10,               //每页显示的记录条数,默认为10 69              pageList: [10, 20, 30, 40, 50],       //可以设置每页记录条数的列表 70              beforePageText: '第',       //页数文本框前显示的汉字 71              afterPageText: '页    共 {pages} 页', 72              displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录', 73              //选择页的处理 74              onSelectPage: function (pageNumber, pageSize) { //按分页的设置取数据 75                 getData(pageNumber, pageSize); 76                 //设置表格的pageSize属性,表格变化时按分页组件设置的pageSize显示数据 77                 $('#person').combogrid("grid").datagrid('options').pageSize = pageSize; 78                 //将隐藏域中存放的查询条件显示在combogrid的文本框中 79                 $('#person').combogrid("setValue", $('#txtId').val()); 80                 $('#txtName').val(''); 81             }, 82             onChangePageSize: function () {}, //改变页显示条数的处理 (处理后还是走onSelectPage事件,所以设置也写到onSelectPage事件中了) 83             onRefresh: function (pageNumber, pageSize) { //点击刷新的处理 84                 getData(pageNumber, pageSize); //按分页的设置取数据 85                 $('#person').combogrid("setValue", $('#txtId').val());//将隐藏域中存放的查询条件显示在combogrid的文本框中 86                 $('#txtName').val(''); 87             } 88         }); 89     } 90          91     var getData = function (page, pagesize) {  92         $.ajax({ 93             type: "POST", 94             url: "${pageContext.request.contextPath}/controller/persons.action", 95             type : "POST", 96             data: { 97                 "page" : page, 98                 "pagesize" : pagesize, 99                 "keyword" : $('#txtId').val()100             }101             error: function (XMLHttpRequest, textStatus, errorThrown) {102                $.messager.progress('close');103             },104             success: function (data) {105                 console.log(typeof data);106                    $('#person').combogrid("grid").datagrid("loadData", $.parseJSON(data));107             }108         }); 109         110     };111 });112 </script>                113                                             114 </body>115 </html>
Copy after login

The background controller is as follows:

/**     * 以json数据返回person列表数据     * @param page 当前页序号     * @param pagesize 页面大小     * @param keyword 要搜索的关键字     * @return json数据     */    @RequestMapping(value = "person")    @ResponseBody    public Map<String, Object> getPersons(@RequestParam("page") int page,            @RequestParam("pagesize") int pagesize,            @RequestParam(value="keyword",required=false) String keyword){                Map<String, Object> result = new HashMap<String, Object>();        int total = personService.countPageByName(kind, keyword);        List<Person> productList = personService.queryPageByName(keyword, pagesize, page);          result.put("total", total);          result.put("rows", productList);         result.put("_pagelines",pagesize);                result.put("_currpage", page);                return result;    }        
Copy after login

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1655
14
PHP Tutorial
1252
29
C# Tutorial
1226
24
Is HTML easy to learn for beginners? Is HTML easy to learn for beginners? Apr 07, 2025 am 12:11 AM

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Apr 04, 2025 pm 11:54 PM

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

What is an example of a starting tag in HTML? What is an example of a starting tag in HTML? Apr 06, 2025 am 12:04 AM

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

How to use CSS3 and JavaScript to achieve the effect of scattering and enlarging the surrounding pictures after clicking? How to use CSS3 and JavaScript to achieve the effect of scattering and enlarging the surrounding pictures after clicking? Apr 05, 2025 am 06:15 AM

To achieve the effect of scattering and enlarging the surrounding images after clicking on the image, many web designs need to achieve an interactive effect: click on a certain image to make the surrounding...

HTML, CSS, and JavaScript: Essential Tools for Web Developers HTML, CSS, and JavaScript: Essential Tools for Web Developers Apr 09, 2025 am 12:12 AM

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

How to implement adaptive layout of Y-axis position in web annotation? How to implement adaptive layout of Y-axis position in web annotation? Apr 04, 2025 pm 11:30 PM

The Y-axis position adaptive algorithm for web annotation function This article will explore how to implement annotation functions similar to Word documents, especially how to deal with the interval between annotations...

See all articles