关于作者:
- 郑云飞, 程序员Java(web前端,web后端,oracle数据库or mysql数据库)
- 艺名:天放
- weibo:@tianFang
- blog: zhengyunfei.iteye.com
- email: zhengyunfei8@gmail.com
下班之余,没事干写的东西吧,最近下班都很晚的,到家也就8,9,10来点了。看个电影时间不够,看个电视剧时间更不够,睡觉吧,目前还不困,那就写点东西吧,总结一下工作一天遇到的问题。
首页我喜欢听着广播,写着博客。先打开咕咕收音机,锁定中国之声。
贴上一张图片,给苍白的博客,增添一些活力,以至于读者朋友们看着不会乏味。
首先。我先想想怎么才能描述清楚这个问题。
我下面要说的是datagrid表格显示的问题。Fuel UX datagrid。先来介绍一下datagrid,官方文档内容如下:
Example
Below is a working datagrid example.
Mexico City | MX | 12294193 | capital of a political entity |
Manila | PH | 10444527 | capital of a political entity |
Dhaka | BD | 10356500 | capital of a political entity |
Seoul | KR | 10349312 | capital of a political entity |
Jakarta | ID | 8540121 | capital of a political entity |
Tokyo | JP | 8336599 | capital of a political entity |
Taipei | TW | 7871900 | capital of a political entity |
Beijing | CN | 7480601 | capital of a political entity |
Bogotá | CO | 7102602 | capital of a political entity |
Hong Kong | HK | 7012738 | capital of a political entity |
Using datagrid
Call the datagrid via javascript:
$('#MyGrid').datagrid({ dataSource: dataSource, stretchHeight: true })
Data Source
Provide a data source to the datagrid to supply column information and data. Your data source must support the following two methods.
columns | (none) | Returns an array of objects containing column information |
data | options (object), callback(function) | The options parameter contains search, sortProperty, sortDirection, pageIndex, and pageSize. Retrieve data then callcallback with an object containing data, start, end, count, pages, and page. View the source of this page for an example static data source. |
Methods
Fuel UX's datagrid exposes a method for reloading the grid.
reload | This method causes the datagrid to reload the data from the dataSource and return to the first page. |
clearSelectedItems | If row selection is enabled, this method will clear all rows currently selected. |
setSelectedItems | If row selection is enabled, this method will programmatically set specified rows within the datagrid by each element's primary key value. The argument passed to this method should be an array of string values. Note, this relies on the _data array being included in the DataSource as provided in the samples directory. |
getSelectedItems | If row selection is enabled, this method returns an object containing all the selected items within the datagrid. Each property in the returned object represents a selected value (by primary key) with the corresponding values being the selected data elements. |
Options
dataSource | See Data Source section above |
null (must be provided) |
dataOptions | Options for current data to be displayed | { pageIndex: 0, pageSize: 10 } |
stretchHeight | Introduced in version 2.2. Enables stretchHeight rendering. This sets the datagrid's height to a stable height, matching its parent element. The appearance of the datagrid becomes much more consistent while rendering and displaying different numbers of rows. Rows will scroll within the table when they exceed the available height. | false |
loadingHTML | HTML for loading indicator | (bootstrap progress indicator) |
itemsText | Text for plural items | items |
itemText | Text for singular item | item |
enableSelect | Boolean value to enable/disable datagrid row selection | false |
primaryKey | If datagrid row selection is enabled, this specifies the property in each data element which should be used as the primary key. |
null (must be provided) |
multiSelect | If datagrid row selection is enabled, multiple rows may selected with a boolean value of true , or disallowed with a value of false . |
true |
Events
Fuel UX's datagrid exposes an event for hooking into its functionality.
loaded | This event is fired after the grid loads or reloads data |
itemSelected | If row selection is enabled, this event is fired when a row is selected. The value of the selected row is returned. |
itemDeselected | If row selection is enabled, this event is fired when a row is deselected. The value of the deselected row is returned. |
但是我感觉官方给的这个文档,写的太过于简单,初学者很难将这个表格动态的显示出来,因为很多人不知道datagrid返回来的数据格式是什么样子的。
下面我们看一下jquery LigerUI的官方文档是如何介绍datagrid表格的。
下面我们点击查看源码:
function f_initGrid() { g = manager = $("#maingrid").ligerGrid({ columns: [ { display: '主键', name: 'ID', width: 50, type: 'int',frozen:true }, { display: '名字', name: 'RealName', editor: { type: 'text' } }, { display: '性别', width: 50, name: 'Sex',type:'int', editor: { type: 'select', data: sexData, valueColumnName: 'Sex' }, render: function (item) { if (parseInt(item.Sex) == 1) return '男'; return '女'; } }, { display: '年龄', name: 'Age', width: 50, type: 'int', editor: { type: 'int'} }, { display: '部门', name: 'DepartmentID', width: 120, isSort: false, editor: { type: 'select', data: DepartmentList, valueColumnName: 'DepartmentID', displayColumnName: 'DepartmentName' }, render: function (item) { for (var i = 0; i < DepartmentList.length; i++) { if (DepartmentList[i]['DepartmentID'] == item.DepartmentID) return DepartmentList[i]['DepartmentName'] } return item.DepartmentName; } } ], onSelectRow: function (rowdata, rowindex) { $("#txtrowindex").val(rowindex); }, enabledEdit: true, clickToEdit: false, isScroll: false, data:EmployeeData, width: '100%' }); }
下面我们再查看一下datagrid的数据格式data:EmployeeData
var EmployeeData = { Rows: [{ "__status": null, "ID": 1, "DepartmentID": 3, "RealName": "fewf", "DepartmentName": "销售部", "Sex": 1, "Age": 2433, "IncomeDay": new Date(1301356800000), "Phone": "159244332", "Address": "变为不为恶" }, { "__status": null, "ID": 2, "DepartmentID": 1, "RealName": "李三34", "DepartmentName": "李白", "Sex": 2, "Age": 23, "IncomeDay": new Date(1301299200000), "Phone": "2323232323", "Address": "3434" }, { "__status": null, "ID": 3, "DepartmentID": 3, "RealName": "吴彬3", "DepartmentName": "销售部", "Sex": 2, "Age": 26, "IncomeDay": new Date(1294128000000), "Phone": "159244332", "Address": "1311飞屋服务费3434343433434" }, { "__status": null, "ID": 5, "DepartmentID": 2, "RealName": "吴久", "DepartmentName": "研发中心", "Sex": 2, "Age": 29, "IncomeDay": new Date(1288569600000), "Phone": "159244332", "Address": "3444444" }, { "__status": null, "ID": 6, "DepartmentID": 3, "RealName": "陈民", "DepartmentName": "销售部", "Sex": 2, "Age": 21, "IncomeDay": new Date(1297728000000), "Phone": null, "Address": "3435333" }, { "__status": null, "ID": 7, "DepartmentID": 3, "RealName": "陈留", "DepartmentName": "销售部", "Sex": 1, "Age": 32, "IncomeDay": new Date(1298851200000), "Phone": null, "Address": "3333444444444444" }, { "__status": null, "ID": 8, "DepartmentID": 1, "RealName": "谢银223", "DepartmentName": "公司", "Sex": 1, "Age": 13, "IncomeDay": new Date(1298880000000), "Phone": null, "Address": "34344555555555" }, { "__status": null, "ID": 10, "DepartmentID": 2, "RealName": "陈元为2", "DepartmentName": "研发中心", "Sex": 2, "Age": 16, "IncomeDay": new Date(1298851200000), "Phone": null, "Address": "34343434343434" }, { "__status": null, "ID": 11, "DepartmentID": 1, "RealName": "大为", "DepartmentName": "公司", "Sex": 1, "Age": 19, "IncomeDay": new Date(1301472000000), "Phone": null, "Address": "3434444444" }, { "__status": null, "ID": 21, "DepartmentID": 4, "RealName": "444", "DepartmentName": "市场部", "Sex": 2, "Age": 20, "IncomeDay": new Date(1298880000000), "Phone": null, "Address": "444" }, { "__status": null, "ID": 22, "DepartmentID": 1, "RealName": "22", "DepartmentName": "公司", "Sex": 1, "Age": 20, "IncomeDay": new Date(1301270400000), "Phone": null, "Address": "22" }, { "__status": null, "ID": 23, "DepartmentID": 2, "RealName": "22", "DepartmentName": "研发中心", "Sex": 1, "Age": 20, "IncomeDay": new Date(1301270400000), "Phone": null, "Address": "2224444444" }, { "__status": null, "ID": 26, "DepartmentID": 4, "RealName": "232323", "DepartmentName": "市场部", "Sex": 2, "Age": 0, "IncomeDay": new Date(1306108800000), "Phone": null, "Address": "222222222222222"}], Total: 13 };
这样就可以很清楚的看到datagrid数据的组成,有Rows和ToTal这2个属性组成,在后台我们只需要查询一个List<Object> 作为datagrid的Rows ,然后再查询List<Object>的size作为datagrid的Total,燃火转换为json个数的数据,这样就很容易的显示datagrid的表格了。
再看看bootstrap的datagrid的官方文档,至少我不知道datagrid表格的格式到底是什么样子的,我怎么返回一个json格式的数据,datagrid才能显示出来。
看看bootstrap datagrid.js也没有看出来datagrid的数据格式到底张什么样子。
好吧,因为我工作中用到这个,我已经知道他张什么样子了。现在就告诉大家吧。
datagrid的格式是这样的:
{ page:1,pages:10,totalCount:30,start:1,end:10,data: [{ "__status": null, "ID": 1, "DepartmentID": 3, "RealName": "fewf", "DepartmentName": "销售部", "Sex": 1, "Age": 2433, "IncomeDay": new Date(1301356800000), "Phone": "159244332", "Address": "变为不为恶" }, { "__status": null, "ID": 2, "DepartmentID": 1, "RealName": "李三34", "DepartmentName": "公司", "Sex": 2, "Age": 23, "IncomeDay": new Date(1301299200000), "Phone": "2323232323", "Address": "3434" }, { "__status": null, "ID": 3, "DepartmentID": 3, "RealName": "吴彬3", "DepartmentName": "销售部", "Sex": 2, "Age": 26, "IncomeDay": new Date(1294128000000), "Phone": "159244332", "Address": "1311飞屋服务费3434343433434" }, { "__status": null, "ID": 5, "DepartmentID": 2, "RealName": "吴久", "DepartmentName": "研发中心", "Sex": 2, "Age": 29, "IncomeDay": new Date(1288569600000), "Phone": "159244332", "Address": "3444444" }, { "__status": null, "ID": 6, "DepartmentID": 3, "RealName": "陈民", "DepartmentName": "销售部", "Sex": 2, "Age": 21, "IncomeDay": new Date(1297728000000), "Phone": null, "Address": "3435333" }, { "__status": null, "ID": 7, "DepartmentID": 3, "RealName": "陈留", "DepartmentName": "销售部", "Sex": 1, "Age": 32, "IncomeDay": new Date(1298851200000), "Phone": null, "Address": "3333444444444444" }, { "__status": null, "ID": 8, "DepartmentID": 1, "RealName": "谢银223", "DepartmentName": "公司", "Sex": 1, "Age": 13, "IncomeDay": new Date(1298880000000), "Phone": null, "Address": "34344555555555" }, { "__status": null, "ID": 10, "DepartmentID": 2, "RealName": "陈元为2", "DepartmentName": "研发中心", "Sex": 2, "Age": 16, "IncomeDay": new Date(1298851200000), "Phone": null, "Address": "34343434343434" }, { "__status": null, "ID": 11, "DepartmentID": 1, "RealName": "大为", "DepartmentName": "公司", "Sex": 1, "Age": 19, "IncomeDay": new Date(1301472000000), "Phone": null, "Address": "3434444444" }, { "__status": null, "ID": 21, "DepartmentID": 4, "RealName": "444", "DepartmentName": "市场部", "Sex": 2, "Age": 20, "IncomeDay": new Date(1298880000000), "Phone": null, "Address": "444" }, { "__status": null, "ID": 22, "DepartmentID": 1, "RealName": "22", "DepartmentName": "公司", "Sex": 1, "Age": 20, "IncomeDay": new Date(1301270400000), "Phone": null, "Address": "22" }, { "__status": null, "ID": 23, "DepartmentID": 2, "RealName": "22", "DepartmentName": "研发中心", "Sex": 1, "Age": 20, "IncomeDay": new Date(1301270400000), "Phone": null, "Address": "2224444444" }, { "__status": null, "ID": 26, "DepartmentID": 4, "RealName": "232323", "DepartmentName": "市场部", "Sex": 2, "Age": 0, "IncomeDay": new Date(1306108800000), "Phone": null, "Address": "222222222222222"}]};
暂时用ligerui datagrid的数据修改了一下。
好了,后台返回这样的格式, datagrid前台只要这样写就可以显示漂亮的表格了:
$('#MyGrid').datagrid({ dataSource: new AjaxDataSource({ columns: [{ property: "loginName", label: '用户名', sortable: true }, { property: 'loginEmail', label: '邮箱号码', sortable: true }, { property: 'province', label: '省', sortable: true }, { property: 'city', label: '市', sortable: true } ,{ property: 'operation', label: '操作', sortable: true , width:'300px' }] }) });
property 只要和后台返回过来的LIst<Bo> Bo的属性相对应,数据就会显示出来,比如loginName,那么在Bo中也有一个属性loginName,但是现在有一个问题,假如provice和city不在Bo里面,而是存在另一个Bo里面假如存在CityBo里面,Bo里面有一个属相cityBo,那么我想显示CityBo里面的provice和city,前台页面 property: 'province',该如何写才能让datagrid显示出来,
理论上通过cityBo.provice就可以显示出来,但是跟预期的不一样,有点让人失望,显示不出来,这样就只能再在Bo里面添加2个属性,provice和city,貌似这样和cityBo重复了。
目前我暂时还是在Bo里面新增2个字段,怎么样不新增字段而是通过cityBo.procice就可以显示在datagrid里面呢?
另外一个问题,如果我想自定义列显示,我们目前是在java类里面自定义一个列,在java类里面拼接字符串,有点不太合理,看下jqueryligerUI的datagrid的自定义列显得比较强大。
{ display: '性别', width: 50, name: 'Sex',type:'int', editor: { type: 'select', data: sexData, valueColumnName: 'Sex' }, render: function (item) { if (parseInt(item.Sex) == 1) return '男'; return '女'; } }
加一个render:funtion就可以自定义列,没必要在java代码里去拼接,而且如果要让表格变为可编辑的,只需要加一个editor就可以了。而且可以自定义列的宽度。类型。
还是bootstrap有这么强大的功能,我没有发现,求赐教。。。。
相关推荐
WPF Datagrid是WPF中一个重要的控件,用于显示和操作表格数据,类似于Windows Forms中的DataGridView。在这个“wpf-datagrid-access DB”主题中,我们将深入探讨如何利用WPF Datagrid与Microsoft Access数据库进行...
标题“easyui datagrid表格打印”关注的就是如何解决这个问题,即如何将经过formatter处理后的数据在打印时保持原有的格式。 在描述中提到的“支持formatter格式化数据的打印”,指的是Datagrid中用于数据美化和...
### easyui的datagrid中editor和combogrid的结合使用 #### 一、easyui简介及...需要注意的是,在实际开发过程中可能还会遇到各种问题,比如兼容性问题、样式调整等,这些都需要开发者根据实际情况进行调试和优化。
在这个特定的场景中,用户遇到了一个问题:当尝试向datagrid-filter插入数据时,组件会错误地显示两个相同的条目。这个问题可能是由于代码逻辑错误或者DOM操作不当导致的。 首先,我们需要了解`datagrid-filter`的...
在使用EasyUI框架进行Web应用开发时,可能会遇到一个常见的问题,即在datagrid、combobox、tree等组件中,如果数据包含HTML标签或特殊字符,这些字符会被当作HTML标签进行解析,导致数据显示不正常或者丢失。...
在使用EasyUI框架进行前端开发的过程中,可能会遇到dataGrid组件在数据为空时列显示不完整的问题。这不仅影响用户体验,也降低了系统的可用性。本文将详细介绍如何解决当dataGrid列较多且无数据显示不全的情况,并...
Flex DataGrid 是 Adobe Flex 框架中的一个组件,它用于在应用程序中显示表格数据。在Flex中,实现数据网格的总计功能是一项常见的需求,它能够帮助用户快速地理解和分析大量数据。本项目提供了一个已经实现了总计...
DataGrid 是一个表格控件,它用于显示和编辑表格形式的数据。DataGrid 支持分页、排序、过滤、行选择、编辑等多种功能,并且可以与后台数据库进行交互,实现数据的增删改查。DataGrid 还支持自定义列、行模板,提供...
在实际应用中,我们常常会遇到一个问题:如何确保`Datagrid`中的表头和列内容正确对齐。标题"datagrid 4种解决table对齐"和描述"datagrid 4种解决方案 表头与列对齐"正是针对这一问题提出的不同解决策略。下面我们将...
EasyUI拥有活跃的社区和丰富的文档资源,开发者可以在遇到问题时查阅官方文档,或在社区提问寻求帮助,以快速解决问题并提升开发效率。 通过以上介绍,我们可以看出EasyUIDataGrid是一个强大的.NET数据网格控件,...
然而,在使用过程中经常会遇到一些常见问题,这些问题如果不妥善解决,可能会严重影响用户体验和系统的稳定性。本文将详细探讨在使用 `jQuery Datagrid` 时遇到的一些常见问题,并提供相应的解决方案。 #### 二、...
同时,开发者社区通常会提供许多实用的教程、问答和示例,帮助解决在开发过程中遇到的问题。 总的来说,Bootstrap的DataGrid组件是Web开发中的一个强大工具,它集成了数据展示、操作和检索的核心功能,能够帮助...
当我们需要根据用户需求或者界面设计调整DataGrid的显示时,可能会遇到需要在运行时显示或隐藏某一列的情况。本文将详细讲解如何在DataGrid中实现这一功能。 首先,我们需要理解DataGrid的基本结构。DataGrid通常...
然而,在实际应用中,有时候从服务器查询不到相关数据,这种情况下,我们通常需要在 datagrid 中显示相应的提示信息,告知用户没有找到数据。 本文将详细介绍如何在 jQuery EasyUI 的 datagrid 中,当没有数据时...
在这个场景中,"c++ MFC DataGrid对数据库显示" 的项目就是针对这个问题的一个解决方案,它利用MFC的DataGrid控件结合SQL Server 2000进行数据展示。 DataGrid控件是MFC中的一个可视化组件,主要用于展示二维表格...
在使用EasyUI开发Web应用时,常常会遇到datagrid表格中操作栏的按钮图标不显示的问题。这通常是由于jQuery EasyUI的自动渲染机制未能正确处理动态加载或Ajax加载的内容导致的。EasyUI Datagrid是一个功能丰富的表格...
首先,Datagrid是Flex中一个非常重要的组件,它用于展示二维数据集,通常用于表格形式的数据展示。在实际项目中,有时我们需要将用户在Datagrid中看到的数据输出到纸上,这就涉及到打印功能的实现。 在Flex中,打印...
在开发基于Adobe Flex的应用程序时,我们经常遇到需要将数据展示在用户友好的方式中,例如使用DataGrid组件。然而,有时用户希望将这些数据显示在更传统的格式中,如Microsoft Excel电子表格。本教程将详细介绍如何...
在本场景中,"datagrid-detailview"可能是一个自定义的JavaScript插件,用于解决原生easyUI库不再提供支持的问题。 EasyUI是一个基于jQuery的轻量级框架,它提供了一系列的UI组件,如datagrid、dialog、form等,...
首先,DataGrid是Silverlight开发中用于创建表格布局并显示大量结构化数据的标准控件。它提供了丰富的功能,如排序、分页、筛选、编辑和格式化等。在Silverlight应用中,DataGrid通常用于企业级应用,用于展示数据库...