HTML代碼:
<!-- 菜單 -->
<div id="mm" class="easyui-menu" style="width:140px;">
</div>
Javascript代碼:
/*綁定右鍵*/
$(".datagrid-cell").live('contextmenu',function(e){//.datagrid-cell 是easyUI表格樣式,這樣設置的原因是,讓菜單在表格上點擊右鍵才顯示
var selectRow=$('#grid').datagrid('getSelected');//獲得選中行數據
//顯示快捷菜單
if(selectRow==null){
Ext.Msg.alert('提示', '請在表格上單擊左鍵選擇一行數據.');
return false;
}
//第一步將集合清空
$('#mm').empty();
//創建菜單
createMenu(selectRow);
// alert($('#mm').children().size());
//沒有子菜單,那么不顯示
if($('#mm').children().size()==0){
return false;
}
//菜單添加完畢顯示菜單
$('#mm').menu('show', {
left: e.pageX,
top: e.pageY
});
return false;
});
創建菜單方法:
//創建菜單
function createMenu(row){
var tjlx = document.getElementById("tjlx").value; // 統計類型 年1 季度2 月3 日4
var collectType=document.getElementById("collectType").value;//統計方式 unit:按單位 Sections 按科室
var orgcode=row.orgcode;
var showtime=row.showtime;
var collectType=document.getElementById("collectType").value;//unit,按單位;Sections,按科室
var officecode="";
if(collectType=='Sections'){
var officecode=row.officecode;
}
//if 01
if(collectType=="unit"){
var dbyear=showtime.substring(0,4);//年度
var exaTimeType="0";
if(tjlx=="2"){
var exaTimeType=showtime.substring(showtime.indexOf("年")+1,showtime.indexOf("季"));//季度
}
if(tjlx=="3"){
var exaTimeType=showtime.substring(showtime.indexOf("年")+1,showtime.indexOf("月"));//月份
}
//綁定點擊事件
$('#mm').menu('appendItem',{id:"m_001",text:"按日期各科室分解"});
$("#m_001").click(function(){
openWin(orgcode,dbyear,tjlx,exaTimeType,officecode,"Sections");
});
}
//if 01
//if 02
if(tjlx=="1"){
var dbyear=showtime.substring(0,4);//年度
//添加點擊事件,onclick:
$('#mm').menu('appendItem',{id:"m_002",text:"按日期各季度分解"});
$("#m_002").click(function(){
openWin(orgcode,dbyear,"2","0",officecode,collectType);
});
}
//if 02
//if 03
//年 按照月度查詢
if(tjlx=="1")
{
var dbyear=showtime.substring(0,4);//年度
//添加點擊事件,onclick:
$('#mm').menu('appendItem',{id:"m_003",text:"按日期各月份分解"});
$("#m_003").click(function(){
openWin(orgcode,dbyear,"3","0",officecode,collectType);
});
}
//if 03
//if 04
//季度按照月查詢
if(tjlx=="2"){
var dbyear=showtime.substring(0,4);//年度
var exaTimeType=showtime.substring(showtime.indexOf("年")+1,showtime.indexOf("季"));//季度
var tempExaTimeType="";
if(exaTimeType=="1")
{
tempExaTimeType="1,2,3";
}
if(exaTimeType=="2")
{
tempExaTimeType="4,5,6";
}
if(exaTimeType=="3")
{
tempExaTimeType="7,8,9";
}
if(exaTimeType=="4")
{
tempExaTimeType="10,11,12";
}
//添加點擊事件,onclick:
$('#mm').menu('appendItem',{id:"m_004",text:"按日期各月份分解"});
$("#m_004").click(function(){
openWin(orgcode,dbyear,"3",tempExaTimeType,officecode,collectType);
});
}
//if 04
}
