<html>
<head>
<meta charset="UTF-8">
<title>Context Menu on DataGrid - jQuery EasyUI Demo</title>
<link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../../themes/icon.css">
<link rel="stylesheet" type="text/css" href="../demo.css">
<script type="text/javascript" src="../../jquery.min.js"></script>
<script type="text/javascript" src="../../jquery.easyui.min.js"></script>
</head>
<body>
<h2>Context Menu on DataGrid</h2>
<p>Right click on the header of DataGrid to display context menu.</p>
<div style="margin:20px 0"></div>
<table id="dg"></table>
<script type="text/javascript">
$(function(){
$('#dg').datagrid({
url: 'datagrid_data1.json',
method: 'get',
title: 'Context Menu on DataGrid',
iconCls: 'icon-save',
width: 700,
height: 250,
fitColumns: true,
singleSelect: true,
columns:[[
{field:'itemid',title:'Item ID',width:80},
{field:'productid',title:'Product ID',width:120},
{field:'listprice',title:'List Price',width:80,align:'right'},
{field:'unitcost',title:'Unit Cost',width:80,align:'right'},
{field:'attr1',title:'Attribute',width:250},
{field:'status',title:'Status',width:60,align:'center'}
]],
toolbar:[{
iconCls: 'icon-add',
handler:function(){
for(var i=0i<5i++){
$('#dg').datagrid('appendRow',{
itemid: '',
productid: '',
listprice: '',
unitcost:'',
attr1:'',
status:''
})
}
}
}]
})
})
</script>
</body>
</html>
可以,但是数据必须是JSON对象,并且符合以下格式:{"total":总记录数,"rows":数据行数组}
例如:
{"total":300,"rows":[{"id":1,"name":"张三"},{"id":2,"name":"李四"}]}
这个JSON数据对象可以是你在页面上自己拼凑出来的,也可以是通过AJAX请求从服务器端响应来的等等,从哪里来的无所谓,只要符合以上格式就行,然后通过DataGrid组件的loadData方法加载,如下(假设data变量值是上面举例的那个数据对象):
$("#demoDataGrid").datagrid("loadData",data)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)