码迷,mamicode.com
首页 > 其他好文 > 详细

标题添加菜单HeaderContextMenu

时间:2016-09-12 12:05:38      阅读:514      评论:0      收藏:0      [点我收藏+]

标签:

<!DOCTYPE html>
<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‘}
]],
onHeaderContextMenu: function(e, field){
e.preventDefault();
if (!cmenu){
createColumnMenu();
}
cmenu.menu(‘show‘, {
left:e.pageX,
top:e.pageY
});
}
});
});
var cmenu;
function createColumnMenu(){
cmenu = $(‘<div/>‘).appendTo(‘body‘);
cmenu.menu({
onClick: function(item){
if (item.iconCls == ‘icon-ok‘){
$(‘#dg‘).datagrid(‘hideColumn‘, item.name);
cmenu.menu(‘setIcon‘, {
target: item.target,
iconCls: ‘icon-empty‘
});
} else {
$(‘#dg‘).datagrid(‘showColumn‘, item.name);
cmenu.menu(‘setIcon‘, {
target: item.target,
iconCls: ‘icon-ok‘
});
}
}
});
var fields = $(‘#dg‘).datagrid(‘getColumnFields‘);
for(var i=0; i<fields.length; i++){
var field = fields[i];
var col = $(‘#dg‘).datagrid(‘getColumnOption‘, field);
cmenu.menu(‘appendItem‘, {
text: col.title,
name: field,
iconCls: ‘icon-ok‘
});
}
}
</script>
</body>
</html>

 

标题添加菜单HeaderContextMenu

标签:

原文地址:http://www.cnblogs.com/huangf714/p/5863980.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!