ExtJS4 Grid改变单元格背景颜色及Column render学习
程序员文章站
2022-03-07 11:20:18
利用的是column的render
先看效果图:
代码如下:复制代码 代码如下:
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<link href="../extjs-4.1.0/resources/css/ext-all.css" rel="stylesheet" type="text/css" />
<script src="../extjs-4.1.0/bootstrap.js" type="text/javascript"></script>
<style type="text/css">
.x-grid-cell.user-online
{
background-color: #9fc;
}
.x-grid-cell.user-offline
{
background-color: blue;
}
</style>
<script type="text/javascript">
ext.onready(function () {
ext.widget('grid', {
title: 'users',
store: {
fields: ['name', 'email', 'online'],
data: [
{ 'name': '王俊伟', 'email': 'wangjunwei1@163.com', 'online': true },
{ 'name': '王俊伟1', 'email': 'wangjunwei2@163.com', 'online': false },
{ 'name': '王俊伟2', 'email': 'wangjunwei3@163.com', 'online': false },
{ 'name': '王俊伟3', 'email': 'wangjunwei4@163.com', 'online': true }
]
},
columns: [
{
header: 'name',
dataindex: 'name',
renderer: function (value, meta, record) {
meta.tdcls = record.get("online") ? 'user-online' : 'user-offline';
return value;
}
},
{ header: 'email', dataindex: 'email', flex: 1 },
{ header: 'online', dataindex: 'online' }
],
width: 400,
renderto: ext.getbody()
});
});
</script>
</head>
<body>
</body>
</html>
利用的是column的render
先看效果图:
代码如下:
复制代码 代码如下:
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<link href="../extjs-4.1.0/resources/css/ext-all.css" rel="stylesheet" type="text/css" />
<script src="../extjs-4.1.0/bootstrap.js" type="text/javascript"></script>
<style type="text/css">
.x-grid-cell.user-online
{
background-color: #9fc;
}
.x-grid-cell.user-offline
{
background-color: blue;
}
</style>
<script type="text/javascript">
ext.onready(function () {
ext.widget('grid', {
title: 'users',
store: {
fields: ['name', 'email', 'online'],
data: [
{ 'name': '王俊伟', 'email': 'wangjunwei1@163.com', 'online': true },
{ 'name': '王俊伟1', 'email': 'wangjunwei2@163.com', 'online': false },
{ 'name': '王俊伟2', 'email': 'wangjunwei3@163.com', 'online': false },
{ 'name': '王俊伟3', 'email': 'wangjunwei4@163.com', 'online': true }
]
},
columns: [
{
header: 'name',
dataindex: 'name',
renderer: function (value, meta, record) {
meta.tdcls = record.get("online") ? 'user-online' : 'user-offline';
return value;
}
},
{ header: 'email', dataindex: 'email', flex: 1 },
{ header: 'online', dataindex: 'online' }
],
width: 400,
renderto: ext.getbody()
});
});
</script>
</head>
<body>
</body>
</html>