jQuery EasyUI数据表格之一

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP '002.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<script type="text/javascript" src="js/jquery.min.js"></script>
	<link type="text/css" rel="stylesheet" href="js/themes/default/easyui.css"/>
	<link type="text/css" rel="stylesheet" href="js/themes/icon.css"/> 
	<link type="text/css" rel="stylesheet" href="js/demo/demo.css"/>
	<script src="js/jquery.easyui.min.js"></script>
  </head>
  
  <body>
    <h2>基本数据表格</h2>
    <p>这个基本的数据表格</p>
    <div style=="margin:20px 0"></div>
    <table class="easyui-datagrid" title="基本数据表格" style="width:700px; height:250px;" data-options="singleSelect:true,collapsible:true,url:'datagrid_data1.json',method:'get'">
    	<thead>
    		<tr>
    			<th data-options="field:'itemid',width:80">编号</th>
    			<th data-options="field:'product',width:100">产品</th>
    			<th data-options="field:'listprice',width:100">标价</th>
    			<th data-options="field:'unitprice',width:100">成本</th>
    			<th data-options="field:'attribute',width:100">属性</th>
    			<th data-options="field:'status',width:100">状态</th>
    		</tr>
    	</thead>
    </table>
  </body>
</html>

效果如下:


这个图片怎么回事呢?

经过分析,第一次是没有数据源的问题,在目录下缺少data_grid1.json文件

经过加上文件后还没有出来效果,发现是MyEclipse web Browser里面没有出来效果,换成Firefox浏览器,OK。


2.继续研究官方的文档,发现有关于单元格变色的东东哦。

<table class="easyui-datagrid" title="数据表格样式案例" style="width:700px;height:250px"
   		data-options="singleSelect:true,
   					  iconCls:'icon_save',
   					  url:'datagrid_data1.json',
   					  method:'get'"
   	>
   	<thead>
   	<tr>
   		<th data-options="field:'itemid',width:100">项目编码</th>
   		<th data-options="field:'productid',width:80">产品编号</th>
   		<th data-options="field:'listprice',width:100,align:'center',styler:cellStyler">列表价格</th>
   		<th data-options="field:'unitcost',width:100">成本价格</th>
   		<th data-options="field:'attr1',width:100">属性</th>
   		<th data-options="field:'status',width:100,align:'center'">状态</th>
   	</tr>
   	</thead>
   </table>
   <script type="text/javascript">
   		function cellStyler(value,row,index){
   			if(value<30)
   				return 'background:#f00;color:yellow';
   		}
   </script>


主要用到了技术知识点是,styler,指向了cellStyler函数。

单元格styler(样式)函数,返回如'background:red'这样的自定义单元格样式字符串。该函数带3个参数:
value:字段值。
row:行记录数据。
index: 行索引。

代码示例:

$('#dg').datagrid({
	columns:[[
		{field:'listprice',title:'List Price', width:80, align:'right',
			styler: function(value,row,index){
				if (value < 20){
					return 'background-color:#ffee00;color:red;';
				}
			}
		}
	]]
});


视频课:https://edu.csdn.net/course/play/7621
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

teayear

读后有收获可以支付宝请作者喝咖

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值