easy_UI datagrid view数据格式化
从数据库中提取的信息,有时候需要后期处理一下,easy_ui给了我们很好的一个方法,根据easy_ui生成datagridview的两种方式,下面用两种方式来格式化显示数据信息
1,通过脚本生成的datagridview,这个时候在制定列属性的时候,我们可以添加formatter方法,如下所示
$('#gridTable').datagrid({
title: '系统通知及广告管理',
loadMsg:'数据加载中,请稍后……',
rownumbers: true,
pagination: true,
singleSelect: false,
pageSize: 10,
pageList: [5, 10, 15, 20],
fitColumns: true,
fit: true,
striped: true,
nowrap: false,
url: 'list.do',
idField:'mediaId',
columns:[[
{field:'id',checkbox:true},
{field:'system',title:'适用系统'},
{field:'infoType',title:'消息类型',
formatter:
function(value, row, index){
if(value==1)
return "文本";
if(value==2)
return "图片";
if(value==3)
return "视频";
else
return "<span style=\"color:red\" >未知</span>";
}},
{field:'title',title:'标题'},
{field:'content',title:'内容',width:140},
{field:'issueTime',title:'生效时间',
formatter:function(value,row,index){
var unixTimestamp = new Date(value);
return unixTimestamp.toLocaleString();
}
},
{field:'disabledTime',title:'失效时间'},
{field:'userId',title:'用户ID'},
{field:'userName',title:'操作员'}
]],
用这样的方式生成格式化时间和显示内容,
第二种方法,直接生成table,然后给formatter制定方法
<table id="dg" title="用户信息管理" class="easyui-datagrid" style="width:100%;height:95%"
url="/sysuser/queryAllUser"
toolbar="#toolbar" pagination="true"
rownumbers="true" fitColumns="true" singleSelect="true">
<thead>
<tr>
<th field="userId" width="50">用户编号</th>
<th field="unitName" width="50">用户单位</th>
<th field="userName" width="50">用户名字</th>
<th field="lastLoginDate" formatter="jsonTimeStamp" width="50">上次登录时间</th>
<th field="isLocked" width="50" formatter="formatlock">是否锁定</th>
</tr>
</thead>
</table>
此时的jsonTimeStamp和formatlock方法如下,将其放入html的scrpits下或者单独做一个common.js
/**
* @param value 将用户的状态信息解析为汉字状态信息
* @author lyy
* @desc 0-未锁定 1-锁定
*/
function formatlock(value){
if(value==0)
return "<span style=\"color:green\" >未锁定</span>";
else
return "<span style=\"color:red\" >锁定</span>";
}
/**
* @param milliseconds 要转换的时间豪秒数
* @author lyy
* @desc 将毫秒时间转换为2010-1-1 1:1:1这样的格式
*/
function jsonTimeStamp(milliseconds) {
if (milliseconds != "" && milliseconds != null && milliseconds != "null") {
var datetime = new Date();
datetime.setTime(milliseconds);
var year = datetime.getFullYear();
var month = datetime.getMonth() + 1 < 10 ? "0"
+ (datetime.getMonth() + 1) : datetime.getMonth() + 1;
var date = datetime.getDate() < 10 ? "0" + datetime.getDate()
: datetime.getDate();
var hour = datetime.getHours() < 10 ? "0" + datetime.getHours()
: datetime.getHours();
var minute = datetime.getMinutes() < 10 ? "0"
+ datetime.getMinutes() : datetime.getMinutes();
var second = datetime.getSeconds() < 10 ? "0"
+ datetime.getSeconds() : datetime.getSeconds();
return year + "-" + month + "-" + date + " " + hour + ":" + minute
+ ":" + second;
} else {
return "";
}
}
easy_UI datagrid view数据格式化的更多相关文章
- easyui数据网格视图(Datagrid View)的简单应用
下面介绍datagrid的数据网格详细视图和数据网格的分组视图 1.先引用的js和css文件 1)包含eauyui必备的四个文件easyui.css,icon.css, jquery-min.js.j ...
- SpringMVC框架下数据的增删改查,数据类型转换,数据格式化,数据校验,错误输入的消息回显
在eclipse中javaEE环境下: 这儿并没有连接数据库,而是将数据存放在map集合中: 将各种架包导入lib下... web.xml文件配置为 <?xml version="1. ...
- PHP json数据格式化方法
php 的json_encode能把数组转换为json格式的字符串.字符串没有缩进,中文会转为unicode编码,例如\u975a\u4ed4.人阅读比较困难.现在这个方法在json_encode的基 ...
- easyui 的 DataGrid View 使用
easyui真是后台人员的宝呀,让不会前台的程序员,不用再用那些自己看着都恶心的表格了! 今天来说说easyui datagrid 的 数据表格详细展示表格,这个有趣多了! 先上图 然后是代码 $(' ...
- SpringMVC(三)-- 视图和视图解析器、数据格式化标签、数据类型转换、SpringMVC处理JSON数据、文件上传
1.视图和视图解析器 请求处理方法执行完成后,最终返回一个 ModelAndView 对象 对于那些返回 String,View 或 ModeMap 等类型的处理方法,SpringMVC 也会在内部将 ...
- python数据格式化之pprint
python数据格式化之pprint 2017年06月17日 13:56:33 阅读数:2291 简介 pprint模块 提供了打印出任何Python数据结构类和方法. 模块方法: 1.class p ...
- SpringMVC的数据转换&&数据格式化&&数据校验
1 SpringMVC的数据绑定流程 SpringMVC将ServletRequest对象及目标方法的入参实例传递给WebDataBinderFactory实例,以创建DataBinder实例对象. ...
- jQuery easyui datagrid 的数据加载
其实easyuidatagrid加载数据只有两种方式:一种是ajax加载目标url返回的json数据:另一种是加载js对象,也就是使用loadDate方法,这种方法用于加载本地js数据(非ur ...
- SpringMVC 数据转换 & 数据格式化 & 数据校验
数据绑定流程 1. Spring MVC 主框架将 ServletRequest 对象及目标方法的入参实例传递给 WebDataBinderFactory 实例,以创建 DataBinder 实例对象 ...
随机推荐
- FindFirstVolume系列函数遍历驱动器,获取驱动器信息
什么是“卷”?卷,又称为“逻辑驱动器”,是 NTFS, FAT32 等文件系统组织结构的最高层.卷是存储设备(如硬盘)上由文件系统管理的一块区域,是在逻辑上相互隔离的存储单元.一个磁盘分区至少包含一个 ...
- 【spring boot】spring boot中使用定时任务配置
spring boot中使用定时任务配置 =============================================================================== ...
- lsof/fuser卸载挂载文件
Linux如何卸载挂载文件 在我们进行远程文件操作的时候,我们经常会出现文件服务出现卸载掉哦情况.例如 umount /mnt/net1umount: /mnt/net1: device is b ...
- Zabbix的SNMPTrap监控配置
SNMPTrap监控主要用于设备发生故障时的主动通知的监控.以下简单记录下Zabbix的SNMPTrap的配置方法. 一.SNMPTrap监控的处理流程说明 1.监控对象发送SNMPTrap信息到sn ...
- 使用Spring进行远程访问与Web服务
1.1. 简介 Spring为各种远程访问技术的集成提供了整合类.Spring使得开发具有远程访问功能的服务变得相当容易,而这些远程访问服务由普通Spring POJO实现.目前,Spring支持 ...
- 固定标题列、标题头table
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Yii2系列教程六:集成编辑器
上一篇文章我们实现了简单的用户权限管理,至于更先进的RBAC,我后面会单独出一篇文章来说说.在这一篇文章当中,我主要想写的是在Yii2中集成一个编辑器,因为在我们的实际开发当中,一个简单的textar ...
- 【重点突破】—— fetch()方法介绍
前言:ant-design-pro的技术组成主要是react+redux+dva+antd+fetch+roadhog,dva在源码包index.js里面导出了fetch,但是如果不想使用fetch库 ...
- (转)Netty : writeAndFlush的线程安全及并发问题
rocketmq用netty实现的网络连接,发现它多个线程掉用一个channel连接,所以这个是线程安全的? 使用Netty编程时,我们经常会从用户线程,而不是Netty线程池发起write操作,因为 ...
- 基于Maven的SpringBoot项目实现热部署的两种方式
转载:http://blog.csdn.net/tengxing007/article/details/72675168 前言 JRebel是JavaEE中比较流行的热部署插件,可快速实现热部署,节省 ...