How to implement a table across rows and columns in jQuery easyUI
Code:
Part of page access data
$(function (){ $('#dg').datagrid({ url:'tableController.do?getTable&field=itemid,productid,listprice,unitcost,attr1,status', singleSelect:true, collapsible:true,//收起表格的内容 width: 700, height: 450, loadMsg: '数据加载中...', singleSelect:true, fitColumns:true, rownumbers: true,//显示行数 idField: 'itemid', pagination:true,//显示分页 pageSize:20, pageNumber:1, pageList:[20,40,60,80,100], columns:[[ {field:'',title:'95598账目计算表',colspan:6,align:'center',height:30} ],[ {field:'itemid',title:'部门名称',rowspan:2,align:'center'}, {field:'',title:'统计各部门的账目总和:50亿美元',colspan:5,align:'right'} ],[ {field:'productid',title:'目录',width:100,align:'center'}, {field:'listprice',title:'部门一',width:100,align:'center'}, {field:'unitcost',title:'部门二',width:100,align:'center'}, {field:'attr1',title:'部门三',width:100,align:'center'}, {field:'status',title:'部门四',width:100,align:'center'} ]], onLoadSuccess: function (data) { if (data.rows.length > 0) { //调用mergeCellsByField()合并单元格 mergeCellsByField("dg", "itemid"); // 重新载入当前页面数据 setTimeout("$('#dg').datagrid('reload');",5000); } } }); $('#dg').datagrid('getPager').pagination({ beforePageText:'', afterPageText:'/{pages}', displayMsg:'{from}-{to}共 {total}条', showPageList:true, showRefresh:true, onBeforeRefresh:function(pageNumber, pageSize){ $(this).pagination('loading'); $(this).pagination('loaded'); } });
/**
* EasyUI DataGrid dynamically merges cells based on fields
* Parameter tableID The id of the table to be merged
* Parameter colList The columns to be merged, separated by commas (for example: "name, department, office");
*/
function mergeCellsByField(tableID, colList) { var ColArray = colList.split(","); var tTable = $("#" + tableID); var TableRowCnts = tTable.datagrid("getRows").length; var tmpA; var tmpB; var PerTxt = ""; var CurTxt = ""; var alertStr = ""; for (j = ColArray.length - 1; j >= 0; j--) { PerTxt = ""; tmpA = 1; tmpB = 0; for (i = 0; i <= TableRowCnts; i++) { if (i == TableRowCnts) { CurTxt = ""; } else { CurTxt = tTable.datagrid("getRows")[i][ColArray[j]]; } if (PerTxt == CurTxt) { tmpA += 1; } else { tmpB += tmpA; tTable.datagrid("mergeCells", { index: i - tmpA, field: ColArray[j], //合并字段 rowspan: tmpA, colspan: null }); tTable.datagrid("mergeCells", { //根据ColArray[j]进行合并 index: i - tmpA, field: "Ideparture", rowspan: tmpA, colspan: null }); tmpA = 1; } PerTxt = CurTxt; } } }
For the back-end simulated data, as long as the front-end can receive the data, display the most basic table and call mergeCellsByField(tableID, colList)
, it will merge the cells after the data is loaded. The data is just for testing whether it can be displayed correctly
/**
* *
* Test the method of displaying table content
* @return
*/
@RequestMapping(params = "getTable") public void getTable(HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) { List<Map<String, Object>> listResults=new ArrayList<Map<String,Object>>(); String[] str = {"满意数","不满意数","满意率","合计","部门的总共数","部门满意率"}; String[] item = {"满意度","消息","评价","总计"}; int j = 0;int k = 0; try { for (int i = 0; i < 24 ; i++) { Map<String, Object> map = new HashMap<String, Object>(); if(i/6==j){ map.put("itemid", item[j]); map.put("productid", str[k]); map.put("listprice", new Random().nextInt(100)); map.put("unitcost", new Random().nextInt(100)); map.put("attr1", new Random().nextInt(100)); map.put("status", new Random().nextInt(100)); k++; }else{ ++j; k=0; map.put("itemid", item[j]); map.put("productid", str[k]); map.put("listprice", new Random().nextInt(100)); map.put("unitcost", new Random().nextInt(100)); map.put("attr1", new Random().nextInt(100)); map.put("status", new Random().nextInt(100)); k++; } listResults.add(map); } int page = dataGrid.getPage(); int rows = dataGrid.getRows(); List<Map<String, Object>> listResultsEnd=new ArrayList<Map<String,Object>>(); for (int i = (page-1)*rows; i < page*rows; i++) { if(listResults.size()>=(i+1)){ listResultsEnd.add(listResults.get(i)); } } dataGrid.setResults(listResultsEnd); dataGrid.setTotal(listResults.size()); TagUtil.datagrid(response, dataGrid); } catch (Exception e) { e.printStackTrace(); } }
The above is the detailed content of How to implement a table across rows and columns in jQuery easyUI. For more information, please follow other related articles on the PHP Chinese website!

JavaandJavaScriptaredistinctlanguages:Javaisusedforenterpriseandmobileapps,whileJavaScriptisforinteractivewebpages.1)Javaiscompiled,staticallytyped,andrunsonJVM.2)JavaScriptisinterpreted,dynamicallytyped,andrunsinbrowsersorNode.js.3)JavausesOOPwithcl

JavaScript core data types are consistent in browsers and Node.js, but are handled differently from the extra types. 1) The global object is window in the browser and global in Node.js. 2) Node.js' unique Buffer object, used to process binary data. 3) There are also differences in performance and time processing, and the code needs to be adjusted according to the environment.

JavaScriptusestwotypesofcomments:single-line(//)andmulti-line(//).1)Use//forquicknotesorsingle-lineexplanations.2)Use//forlongerexplanationsorcommentingoutblocksofcode.Commentsshouldexplainthe'why',notthe'what',andbeplacedabovetherelevantcodeforclari

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 English version
Recommended: Win version, supports code prompts!

Notepad++7.3.1
Easy-to-use and free code editor

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
