easyUI 数据表格-datagrid
2015年9月28日
<!DOCTYPE html>
<html>
<head>
<metacharset="UTF-8">
<!-- easyUI library -->
<linkrel="stylesheet" type="text/css"
href="easyui/jquery-easyui-1.4.3/themes/default/easyui.css"/>
<linkrel="stylesheet" type="text/css"
href="easyui/jquery-easyui-1.4.3/themes/icon.css" />
<!-- add defaulticons.@author:[email protected] @date:2015-9-23 14:19 -->
<linkrel="stylesheet" type="text/css"
href="easyui/jquery-easyui-1.4.3/themes/color.css"/>
<scripttype="text/javascript"
src="easyui/jquery-easyui-1.4.3/jquery.min.js"></script>
<scripttype="text/javascript"
src="easyui/jquery-easyui-1.4.3/jquery.easyui.min.js"></script>
<scripttype="text/javascript"
src="easyui/jquery-easyui-1.4.3/locale/easyui-lang-zh_CN.js"></script>
<title>This is a testpage for easyUI</title>
</head>
<body>
<table class="easyui-datagrid"data-options="fitColumns:true,singleSelect:true"style="width:200px;">
<thead>
<tr>
<thdata-options="field:'code'">code</th>
<thdata-options="field:'name'">name</th>
<thdata-options="field:'price'">price</th>
</tr>
</thead>
<tbody>
<tr>
<td>01</td>
<td>02</td>
<td>03</td>
</tr>
<tr>
<td>11</td>
<td>12</td>
<td>13</td>
</tr>
</tbody>
</table>
</body>
</html>
由于JS创建能够设置复杂的样式,推荐使用js创建。
参见:流程:创建table,设置为easyui-datagrid。设置属性和数据。
示例:使用table标签构建样式。
//easyUITest.html
<!DOCTYPE html>
<html>
<head>
<metacharset="UTF-8">
<!-- easyUI library -->
<linkrel="stylesheet" type="text/css"
href="easyui/jquery-easyui-1.4.3/themes/default/easyui.css"/>
<linkrel="stylesheet" type="text/css"
href="easyui/jquery-easyui-1.4.3/themes/icon.css"/>
<!-- add defaulticons.@author:[email protected] @date:2015-9-23 14:19 -->
<linkrel="stylesheet" type="text/css"
href="easyui/jquery-easyui-1.4.3/themes/color.css"/>
<scripttype="text/javascript"
src="easyui/jquery-easyui-1.4.3/jquery.min.js"></script>
<scripttype="text/javascript"
src="easyui/jquery-easyui-1.4.3/jquery.easyui.min.js"></script>
<scripttype="text/javascript"
src="easyui/jquery-easyui-1.4.3/locale/easyui-lang-zh_CN.js"></script>
<scripttype="text/javascript"src="js/highcharts.js"></script>
<scripttype="text/javascript"src="js/highcharts-3d.js"></script>
<title>This is a testpage for easyUI</title>
</head>
<body>
<table id="dg" class="easyui-datagrid"
data-options="fitColumns:true,singleSelect:true,url:'/thbd/pages/BusinessStatistics/clsxxtj_data.json'"
style="width: 100%;">
<thead>
<tr>
<thdata-options="field:'cph'" style="width: 100px;">车牌号</th>
<thdata-options="field:'cpys'" style="width: 100px;">车牌颜色</th>
<thdata-options="field:'ssqy'" style="width: 100px;">所属企业</th>
<thdata-options="field:'sxzs'" style="width: 100px;">上线总数</th>
<thdata-options="field:'xxzs'" style="width: 100px;">下线总数</th>
<thdata-options="field:'cz',formatter:czRowFormatter"
style="width:100px;">操作</th>
</tr>
</thead>
</table>
<script type="text/javascript">
//format cell to <a> with blue color and underline
function czRowFormatter(value, row, index) {
return "<a href=''style='color:blue;text-decoration:underline;'>"
+ value + "</a>";
}
</script>
</body>
</html>
//clsxxtj_data.json
{"total":4,"rows":[
{"cph":"京APB-25415","cpys":"黄色","ssqy":"天绘北斗","sxzs":"1","xxzs":"36","cz":"查看"},
{"cph":"京APB-25415","cpys":"黄色","ssqy":"天绘北斗","sxzs":"1","xxzs":"36","cz":"查看"},
{"cph":"京APB-25415","cpys":"黄色","ssqy":"天绘北斗","sxzs":"1","xxzs":"36","cz":"查看"},
{"cph":"京APB-25415","cpys":"黄色","ssqy":"天绘北斗","sxzs":"0","xxzs":"36","cz":"查看"}
]}
方法:在html中构建table,使用js设置table的样式和数据。
设置样式Columns:参见复杂表头:多栏表头设计
示例:使用js创建表格。
//easyUITest.html
<!DOCTYPE html>
<html>
<head>
<metacharset="UTF-8">
<!-- easyUI library -->
<linkrel="stylesheet" type="text/css"
href="easyui/jquery-easyui-1.4.3/themes/default/easyui.css"/>
<linkrel="stylesheet" type="text/css"
href="easyui/jquery-easyui-1.4.3/themes/icon.css"/>
<!-- add defaulticons.@author:[email protected] @date:2015-9-23 14:19 -->
<linkrel="stylesheet" type="text/css"
href="easyui/jquery-easyui-1.4.3/themes/color.css"/>
<scripttype="text/javascript"
src="easyui/jquery-easyui-1.4.3/jquery.min.js"></script>
<scripttype="text/javascript"
src="easyui/jquery-easyui-1.4.3/jquery.easyui.min.js"></script>
<scripttype="text/javascript"
src="easyui/jquery-easyui-1.4.3/locale/easyui-lang-zh_CN.js"></script>
<scripttype="text/javascript"src="js/highcharts.js"></script>
<scripttype="text/javascript"src="js/highcharts-3d.js"></script>
<title>This is a testpage for easyUI</title>
</head>
<body>
<table id="dg" class="easyui-datagrid"style="width: 100%;"></table>
<script type="text/javascript">
$(document).ready(function() {
$('#dg').datagrid({
url:'/thbd/pages/BusinessStatistics/clsxxtj_data.json',
fitColumns:true,
columns:[[
{field:'cph',title:'车牌号',width:100},
{field:'cpys',title:'车牌颜色',width:100},
{field:'ssqy',title:'所属企业',width:100},
{field:'sxzs',title:'上线总数',width:100},
{field:'xxzs',title:'下线总数',width:100},
{field:'cz',title:'车牌号',width:100,formatter:czRowFormatter}
]]
});
});
//format cell to <a> with blue color and underline
function czRowFormatter(value, row, index) {
return "<a href=''style='color:blue;text-decoration:underline;'>"
+ value + "</a>";
}
</script>
</body>
</html>
//clsxxtj_data.json
{"total":4,"rows":[
{"cph":"京APB-25415","cpys":"黄色","ssqy":"天绘北斗","sxzs":"1","xxzs":"36","cz":"查看"},
{"cph":"京APB-25415","cpys":"黄色","ssqy":"天绘北斗","sxzs":"1","xxzs":"36","cz":"查看"},
{"cph":"京APB-25415","cpys":"黄色","ssqy":"天绘北斗","sxzs":"1","xxzs":"36","cz":"查看"},
{"cph":"京APB-25415","cpys":"黄色","ssqy":"天绘北斗","sxzs":"0","xxzs":"36","cz":"查看"}
]}
//easyUITest.html
<!DOCTYPE html>
<html>
<head>
<metacharset="UTF-8">
<!-- easyUI library -->
<linkrel="stylesheet" type="text/css"
href="easyui/jquery-easyui-1.4.3/themes/default/easyui.css"/>
<linkrel="stylesheet" type="text/css"
href="easyui/jquery-easyui-1.4.3/themes/icon.css"/>
<!-- add defaulticons.@author:[email protected] @date:2015-9-23 14:19 -->
<linkrel="stylesheet" type="text/css"
href="easyui/jquery-easyui-1.4.3/themes/color.css" />
<scripttype="text/javascript"
src="easyui/jquery-easyui-1.4.3/jquery.min.js"></script>
<scripttype="text/javascript"
src="easyui/jquery-easyui-1.4.3/jquery.easyui.min.js"></script>
<scripttype="text/javascript"
src="easyui/jquery-easyui-1.4.3/locale/easyui-lang-zh_CN.js"></script>
<scripttype="text/javascript"src="js/highcharts.js"></script>
<scripttype="text/javascript"src="js/highcharts-3d.js"></script>
<title>This is a testpage for easyUI</title>
</head>
<body>
<table id="dg" class="easyui-datagrid"style="width: 100%;"></table>
<script type="text/javascript">
$(document).ready(function() {
$('#dg').datagrid({
url:'/thbd/pages/BusinessStatistics/clsxxtj_data.json',
fitColumns:true,
columns:[
[
{title:'t1',colspan:3},
{title:'t2',colspan:3}
],
[
{title:'t3',colspan:2},
{title:'t4',colspan:1}
],
[
{field:'cph',title:'车牌号',width:100},
{field:'cpys',title:'车牌颜色',width:100},
{field:'ssqy',title:'所属企业',width:100},
{field:'sxzs',title:'上线总数',width:100},
{field:'xxzs',title:'下线总数',width:100},
{field:'cz',title:'车牌号',width:100,formatter:czRowFormatter}
]
]
});
});
//format cell to <a> with blue color and underline
function czRowFormatter(value, row, index) {
return "<a href=''style='color:blue;text-decoration:underline;'>"
+ value + "</a>";
}
</script>
</body>
</html>
//clsxxtj_data.json
{"total":4,"rows":[
{"cph":"京APB-25415","cpys":"黄色","ssqy":"天绘北斗","sxzs":"1","xxzs":"36","cz":"查看"},
{"cph":"京APB-25415","cpys":"黄色","ssqy":"天绘北斗","sxzs":"1","xxzs":"36","cz":"查看"},
{"cph":"京APB-25415","cpys":"黄色","ssqy":"天绘北斗","sxzs":"1","xxzs":"36","cz":"查看"},
{"cph":"京APB-25415","cpys":"黄色","ssqy":"天绘北斗","sxzs":"0","xxzs":"36","cz":"查看"}
]}
参考:http://www.cnblogs.com/piaopiao7891/p/3180561.html
<thdata-options="field:'checked',checkbox:true" style="width:100px;"></th>
目标:在填充数据时自动调用,返回格式的结果。
方法:formatter(value,rowData,index)。
value:字段值。
rowData:本行所有数据值。
index:行索引。
参考:http://www.bubuko.com/infodetail-286226.html
示例:
//easyUITest.html
<!DOCTYPE html>
<html>
<head>
<metacharset="UTF-8">
<!-- easyUI library -->
<linkrel="stylesheet" type="text/css"
href="easyui/jquery-easyui-1.4.3/themes/default/easyui.css"/>
<link rel="stylesheet"type="text/css"
href="easyui/jquery-easyui-1.4.3/themes/icon.css"/>
<!-- add defaulticons.@author:[email protected] @date:2015-9-23 14:19 -->
<linkrel="stylesheet" type="text/css"
href="easyui/jquery-easyui-1.4.3/themes/color.css"/>
<scripttype="text/javascript"
src="easyui/jquery-easyui-1.4.3/jquery.min.js"></script>
<scripttype="text/javascript"
src="easyui/jquery-easyui-1.4.3/jquery.easyui.min.js"></script>
<scripttype="text/javascript"
src="easyui/jquery-easyui-1.4.3/locale/easyui-lang-zh_CN.js"></script>
<title>This is a testpage for easyUI</title>
</head>
<body>
<table id="t1" class="easyui-datagrid"
data-options="fitColumns:true,singleSelect:true,url:'/thbd/pages/BusinessStatistics/tqjl_data.json'"
style="width: 100%;">
<thead>
<tr>
<thdata-options="field:'checked',checkbox:true"
style="width:100px;"></th>
<th data-options="field:'xh'"style="width: 100px;">序号</th>
<th data-options="field:'cph'"style="width: 100px;">车牌号</th>
<th data-options="field:'tqsj'"style="width: 100px;">提取时间</th>
<th data-options="field:'tqlx'"style="width: 100px;">提取类型</th>
<th data-options="field:'zlxfr'"style="width: 100px;">指令下发人</th>
<th data-options="field:'zt'"style="width: 100px;">状态</th>
<th data-options="field:'cz',formatter:rowFormatter"style="width: 100px;">操作</th>
</tr>
</thead>
</table>
<script type="text/javascript">
functionrowFormatter(value, row, index) {
console.debug(value);
console.debug(row);
console.debug(index);
return"<a href=''>" + value + "</a>";
}
</script>
</body>
</html>
JSON文件格式:单个对象,包括total和rows两个属性。数量使用total指定。数据行使用rows数组指定。每个row作为一个对象,表格列名为属性。
{"total":5,"rows":[
{"code":"c","name":"sf","price":"100"},
{"code":"cpp","name":"sf1","price":"200"},
{"code":"csharp","name":"sf2","price":"300"},
{"code":"java","name":"sf3","price":"400"},
{"code":"python","name":"sf4","price":"500"}
]}
示例:使用JSON数据文件填充表格。
//easyUITest.html
<!DOCTYPE html>
<html>
<head>
<metacharset="UTF-8">
<!-- easyUI library -->
<linkrel="stylesheet" type="text/css"
href="easyui/jquery-easyui-1.4.3/themes/default/easyui.css"/>
<linkrel="stylesheet" type="text/css"
href="easyui/jquery-easyui-1.4.3/themes/icon.css"/>
<!-- add defaulticons.@author:[email protected] @date:2015-9-23 14:19 -->
<linkrel="stylesheet" type="text/css"
href="easyui/jquery-easyui-1.4.3/themes/color.css"/>
<script type="text/javascript"
src="easyui/jquery-easyui-1.4.3/jquery.min.js"></script>
<scripttype="text/javascript"
src="easyui/jquery-easyui-1.4.3/jquery.easyui.min.js"></script>
<scripttype="text/javascript"
src="easyui/jquery-easyui-1.4.3/locale/easyui-lang-zh_CN.js"></script>
<title>This is a testpage for easyUI</title>
</head>
<body>
<table id="t1" class="easyui-datagrid"
data-options="fitColumns:true,singleSelect:true,url:'datagrid_data.json'"
style="width: 200px;">
<thead>
<tr>
<th data-options="field:'code'">code</th>
<thdata-options="field:'name'">name</th>
<thdata-options="field:'price'">price</th>
</tr>
</thead>
</table>
</body>
</html>
//datagrid_data.json
{"total":5,"rows":[
{"code":"c","name":"sf","price":"100"},
{"code":"cpp","name":"sf1","price":"200"},
{"code":"csharp","name":"sf2","price":"300"},
{"code":"java","name":"sf3","price":"400"},
{"code":"python","name":"sf4","price":"500"}
]}
目标:具有合并单元格等多种表头样式。
方法:
设置样式Columns:一个二维数组对象,每一个元素数组代表一行表头。元素数组中的每个对象表示一列,使用colspan表示占用几列(指最后一行的列数),rowspan表示占用几行(几个表头行)。
参考:http://blog.csdn.net/lishuangzhe7047/article/details/42743895
示例:双栏目表头
//create datagrid
//
//@author:[email protected]
//@date:2015-10-14 16:02
function createDataGrid(tid, url, type) {
var frozenColumns = [ [ {
title : '序号',
field : 'xh',
width : 100
}, {
field : 'zz',
title : '组织',
width : 100
}, {
field : 'cph',
title : '车牌号',
width : 100
}, {
field : 'sj',
title : '司机',
width : 100
} ] ];
if (type != 0) {
frozenColumns[0].push({
field : 'rq',
title : '日期',
width : 100
})
}
var cols = {
fitColumns : true,
singleSelect: true,
url : url,
frozenColumns : frozenColumns,
columns : [ [ {
title : '超速',
colspan : 2
}, {
title : '急加速',
colspan : 2
}, {
title : '急减速',
colspan : 2
} , {
title : '疲劳驾驶',
colspan : 2
} , {
title : '空档滑行',
colspan : 2
} ,{
field : 'xskmcs',
title : '行驶开门次数',
width : 100,
rowspan:2
}, {
field : 'ffdh',
title : '非法点火',
width : 100,
rowspan:2
}, {
field : 'ffyw',
title : '非法移位',
width : 100,
rowspan:2
}, {
field : 'hj',
title : '合计',
width : 100,
rowspan:2
}, {
field : 'pm',
title : '排名',
width : 100,
rowspan:2
} ], [ {
field : 'cs-cs',
title : '次数',
width : 100
}, {
field : 'cs-sc',
title : '时长',
width : 100
}, {
field : 'jjs-cs',
title : '次数',
width : 100
}, {
field : 'jjs-sc',
title : '时长',
width : 100
}, {
field : 'jjians-cs',
title : '次数',
width : 100
}, {
field : 'jjians-cs',
title : '时长',
width : 100
}, {
field : 'pljs-cs',
title : '次数',
width : 100
}, {
field : 'pljs-sc',
title : '时长',
width : 100
}, {
field : 'kdhx-cs',
title : '次数',
width : 100
}, {
field : 'kdhx-sc',
title : '时长',
width : 100
}] ]
};
$(tid).datagrid(cols);
}
//easyUITest.html
<!DOCTYPE html>
<html>
<head>
<metacharset="UTF-8">
<!-- easyUI library -->
<linkrel="stylesheet" type="text/css"
href="easyui/jquery-easyui-1.4.3/themes/default/easyui.css"/>
<linkrel="stylesheet" type="text/css"
href="easyui/jquery-easyui-1.4.3/themes/icon.css"/>
<!-- add defaulticons.@author:[email protected] @date:2015-9-23 14:19 -->
<linkrel="stylesheet" type="text/css"
href="easyui/jquery-easyui-1.4.3/themes/color.css"/>
<scripttype="text/javascript"
src="easyui/jquery-easyui-1.4.3/jquery.min.js"></script>
<script type="text/javascript"
src="easyui/jquery-easyui-1.4.3/jquery.easyui.min.js"></script>
<scripttype="text/javascript"
src="easyui/jquery-easyui-1.4.3/locale/easyui-lang-zh_CN.js"></script>
<title>This is a testpage for easyUI</title>
</head>
<body>
<table id="t1" class="easyui-datagrid"
data-options="fitColumns:true,singleSelect:true,url:'/thbd/pages/BusinessStatistics/tqjl_data.json'"
style="width: 100%;">
<thead>
<tr>
<thdata-options="field:'checked',checkbox:true"
style="width:100px;"></th>
<thdata-options="field:'xh'" style="width: 100px;">序号</th>
<thdata-options="field:'cph'" style="width: 100px;">车牌号</th>
<thdata-options="field:'tqsj'" style="width: 100px;">提取时间</th>
<thdata-options="field:'tqlx'" style="width: 100px;">提取类型</th>
<thdata-options="field:'zlxfr'" style="width: 100px;">指令下发人</th>
<thdata-options="field:'zt'" style="width: 100px;">状态</th>
<thdata-options="field:'cz'" style="width: 100px;">操作</th>
</tr>
</thead>
</table>
</body>
</html>
//tqjl_data.json
{"total":4,"rows":[
{"checked":false,"xh":"1","cph":"京APB-25415","tqsj":"100","tqlx":"100","zlxfr":"100","zt":"100","cz":"100"},
{"checked":false,"xh":"2","cph":"京APB-25416","tqsj":"100","tqlx":"100","zlxfr":"100","zt":"100","cz":"100"},
{"checked":true,"xh":"3","cph":"京APB-25417","tqsj":"100","tqlx":"100","zlxfr":"100","zt":"100","cz":"100"},
{"checked":false,"xh":"4","cph":"京APB-25418","tqsj":"100","tqlx":"100","zlxfr":"100","zt":"100","cz":"100"}
]}
参见:流程:创建table,设置为easyui-datagrid。设置属性和数据。
{
"name":"SSN",
"value":"123-456-7890",
"group":"ID Settings",
"editor":{
"type":"combobox",
"options":{
"data":[{"label":"java","value":"j"},{"label":"javascript","value":"js"},{"label":"c++","value":"c"}],
"valueField":"value",
"textField":"label"
}
}
{
"name":"Email",
"value":"[email protected]",
"group":"Marketing Settings",
"editor":{
"type":"validatebox",
"options":{
"validType":"email"
}
}
}
{
"name":"Address",
"value":"0",
"group":"ID Settings",
"editor":{
"type":"checkbox",
"options":{
"on":"kai",
"off":"guan"
}
}
},
{
"name":"age",
"value":"31",
"group":"ID Settings",
"editor":{
"type":"numberbox",
"options":{
"min":18,
"max":100
}
}
},
columns属性设置,一般设置field为value,和name。
columns:[[{field:'name',title:'aaaa'},{field:'value',title:'bbbbbbb',width:'100px'}]],
<!DOCTYPE html>
<html>
<head>
<metacharset="UTF-8">
<!-- easyUI library -->
<linkrel="stylesheet" type="text/css"
href="easyui/jquery-easyui-1.4.3/themes/default/easyui.css"/>
<linkrel="stylesheet" type="text/css"
href="easyui/jquery-easyui-1.4.3/themes/icon.css"/>
<!-- add defaulticons.@author:[email protected] @date:2015-9-23 14:19 -->
<link rel="stylesheet"type="text/css"
href="easyui/jquery-easyui-1.4.3/themes/color.css"/>
<scripttype="text/javascript"
src="easyui/jquery-easyui-1.4.3/jquery.min.js"></script>
<scripttype="text/javascript"
src="easyui/jquery-easyui-1.4.3/jquery.easyui.min.js"></script>
<scripttype="text/javascript"
src="easyui/jquery-easyui-1.4.3/locale/easyui-lang-zh_CN.js"></script>
<title>This is a testpage for easyUI</title>
</head>
<body>
<a id="addRow" class="easyui-linkbutton"style="width: 100px;">addRow</a>
<a id="showHeader"class="easyui-linkbutton" style="width:100px;">showHeader</a>
<a id="hideHeader"class="easyui-linkbutton" style="width:100px;">hideHeader</a>
<a id="showGroup"class="easyui-linkbutton" style="width:100px;">showGroup</a>
<a id="hideGroup"class="easyui-linkbutton" style="width:100px;">hideGroup</a>
<table id="pg"class="easyui-propertygrid" style="width:300px"></table>
<script type="text/javascript">
$(document).ready(function() {
console.debug($('#pg').propertygrid());
$('#pg').propertygrid({
url : '/thbd/pages/xtgl/xtgl_cssz_data.json',
showGroup : true,
scrollbarSize : 0
});
$('#pg').propertygrid({onLoadSuccess:function(e){
var row = {
name : 'addAddress',
value : 'xx222',
group : 'yyyy',
editor : 'checkbox'
};
$('#pg').propertygrid('appendRow', row);
$('#pg').propertygrid('resize', null);
}});
$('#addRow').click(function(e) {
var row = {
name : 'AddName',
value : 'xx',
group : 'Marketing Settings',
editor : 'text'
};
$('#pg').propertygrid('appendRow', row);
});
$('#showHeader').click(function(e){$('#pg').propertygrid({showHeader:true});});
$('#hideHeader').click(function(e){$('#pg').propertygrid({"showHeader":false});});
$('#showGroup').click(function(e){$('#pg').propertygrid({"showGroup":true});});
$('#hideGroup').click(function(e){$('#pg').propertygrid({"showGroup":false});});
});
</script>
</body>
</html>
//easyUITest.html
<!DOCTYPE html>
<html>
<head>
<metacharset="UTF-8">
<!-- easyUI library -->
<linkrel="stylesheet" type="text/css"
href="easyui/jquery-easyui-1.4.3/themes/default/easyui.css"/>
<linkrel="stylesheet" type="text/css"
href="easyui/jquery-easyui-1.4.3/themes/icon.css"/>
<!-- add defaulticons.@author:[email protected] @date:2015-9-23 14:19 -->
<linkrel="stylesheet" type="text/css"
href="easyui/jquery-easyui-1.4.3/themes/color.css"/>
<scripttype="text/javascript"
src="easyui/jquery-easyui-1.4.3/jquery.min.js"></script>
<scripttype="text/javascript"
src="easyui/jquery-easyui-1.4.3/jquery.easyui.min.js"></script>
<scripttype="text/javascript"
src="easyui/jquery-easyui-1.4.3/locale/easyui-lang-zh_CN.js"></script>
<title>This is a testpage for easyUI</title>
</head>
<body>
<a id="addRow" class="easyui-linkbutton"style="width: 100px;">addRow</a>
<a id="showHeader"class="easyui-linkbutton" style="width:100px;">showHeader</a>
<a id="hideHeader"class="easyui-linkbutton" style="width:100px;">hideHeader</a>
<a id="showGroup"class="easyui-linkbutton" style="width:100px;">showGroup</a>
<a id="hideGroup"class="easyui-linkbutton" style="width:100px;">hideGroup</a>
<table id="pg"class="easyui-propertygrid" style="width:300px"></table>
<script type="text/javascript">
$(document).ready(function() {
console.debug($('#pg').propertygrid());
$('#pg').propertygrid({
url : '/thbd/pages/xtgl/xtgl_cssz_data.json',
showGroup : true,
scrollbarSize : 0
});
$('#pg').propertygrid({onLoadSuccess:function(e) {
var row = {
name : 'addAddress',
value : 'xx222',
group : 'yyyy',
editor : 'checkbox'
};
$('#pg').propertygrid('appendRow', row);
$('#pg').propertygrid('resize', null);
}});
$('#addRow').click(function(e) {
var row = {
name : 'AddName',
value : 'xx',
group : 'Marketing Settings',
editor : 'text'
};
$('#pg').propertygrid('appendRow', row);
});
$('#showHeader').click(function(e){$('#pg').propertygrid({showHeader:true});});
$('#hideHeader').click(function(e){$('#pg').propertygrid({"showHeader":false});});
$('#showGroup').click(function(e){$('#pg').propertygrid({"showGroup":true});});
$('#hideGroup').click(function(e){$('#pg').propertygrid({"showGroup":false});});
});
</script>
</body>
</html>
//xtgl_cssz_data.json
{
"total":4,
"rows":[
{
"name":"Name",
"value":"Bill Smith",
"group":"ID Settings",
"editor":"text"
},{
"name":"Address",
"value":"0",
"group":"ID Settings",
"editor":{
"type":"checkbox",
"options":{
"on":"kai",
"off":"guan"
}}},{
"name":"SSN",
"value":"123-456-7890",
"group":"ID Settings",
"editor":{
"type":"combobox",
"options":{
"data":[{"label":"java","value":"j"},{"label":"javascript","value":"js"},{"label":"c++","value":"c"}],
"valueField":"value",
"textField":"label"
}}},{
"name":"age",
"value":"31",
"group":"ID Settings",
"editor":{
"type":"numberbox",
"options":{
"min":18,
"max":100
}}},{
"name":"birth",
"value":"",
"group":"ID Settings",
"editor":"datebox"
},{
"name":"Email",
"value":"[email protected]",
"group":"Marketing Settings",
"editor":{
"type":"validatebox",
"options":{
"validType":"email"
}}}
]
}
//easyUITest.html
<!DOCTYPE html>
<html>
<head>
<metacharset="UTF-8">
<!-- easyUI library -->
<linkrel="stylesheet" type="text/css"
href="easyui/jquery-easyui-1.4.3/themes/default/easyui.css"/>
<linkrel="stylesheet" type="text/css"
href="easyui/jquery-easyui-1.4.3/themes/icon.css"/>
<!-- add defaulticons.@author:[email protected] @date:2015-9-23 14:19 -->
<linkrel="stylesheet" type="text/css"
href="easyui/jquery-easyui-1.4.3/themes/color.css"/>
<script type="text/javascript"
src="easyui/jquery-easyui-1.4.3/jquery.min.js"></script>
<scripttype="text/javascript"
src="easyui/jquery-easyui-1.4.3/jquery.easyui.min.js"></script>
<scripttype="text/javascript"
src="easyui/jquery-easyui-1.4.3/locale/easyui-lang-zh_CN.js"></script>
<title>This is a testpage for easyUI</title>
</head>
<body>
<table id="pg"class="easyui-propertygrid" style="width:536px"></table>
<script type="text/javascript">
$(document).ready(function() {
console.debug($('#pg').propertygrid());
$('#pg').propertygrid({
url : '/thbd/pages/xtgl/xtgl_cssz_data.json',
scrollbarSize : 0,
columns:[[{field:'name',title:'aaaa'},{field:'value',title:'bbbbbbb',width:'100px'}]],
showHeader:false,
showGroup:false
});
});
</script>
</body>
</html>
//xtgl_cssz_data.json
{
"total":4,
"rows":[
{
"name":"兴趣点默认展现",
"value":"展现",
"group":"cssz",
"editor":{
"type":"checkbox",
"options":{
"on":"展现",
"off":"不展现"
}
}
},
{
"name":"实时告警列表最大记录数(1~10000)",
"value":"5000",
"group":"cssz",
"editor":{
"type":"numberbox",
"options":{
"min":1,
"max":10000
}
}
},
{
"name":"实时数据列表最大记录数(1~10000)",
"value":"5000",
"group":"cssz",
"editor":{
"type":"numberbox",
"options":{
"min":1,
"max":10000
}
}
},
{
"name":"实时告警、实时数据、轨迹回放中数据列表默认高度(记录数)(1~20)",
"value":"10",
"group":"cssz",
"editor":{
"type":"numberbox",
"options":{
"min":1,
"max":20
}
}
}
]
}