jQuery EasyUI的DataGrid 数据行上右键问题

如下图:

我想查看单行数据(如ID为20)的右键上获取该行的值,代码:

JavaScript code
 
<script type="text/javascript">
$(
function(){ $('#test').datagrid({ title:'DataGrid数据列表', iconCls:'icon-grid', fit:true, collapsible:true, closable:true, nowrap: false, animate:true, url: '<%=rootPath%>data/getJobs', idField:'id', pagination: true, pageSize:20, pageList: [10,20,30,40,50,100], onRowContextMenu: onRowContextMenu, //右键。[表头(tab)右键onHeaderContextMenu,树形(tree)右键onContextMenu] rownumbers: true, singleSelect: true, columns:[[ {title:'',field:'ck',width:120,checkbox:true}, {field:'id',title:'岗位ID',width:80}, {field:'job_name',title:'岗位名称',width:80}, {field:'dat',title:'入职日期',width:80,align:'right'}, {field:'work_address',title:'工作地点',width:80}, {field:'salary',title:'薪资',width:80,align:'right'}, {field:'status',title:'状态',width:60}, ]], onLoadSuccess: function() { delete $(this).datagrid('options').queryParams['id']; } }); }); </script>

右键菜单:

XML/HTML code
<div id="mm" class="easyui-menu" style="width:120px;">
    <div onClick="view()" data-options="iconCls:'icon-search'">查看</div>
    <div onClick="add()" data-options="iconCls:'icon-add'">新增</div>
    <div onClick="edit()" data-options="iconCls:'icon-edit'">编辑</div>
    <div onClick="del()" data-options="iconCls:'icon-remove'">删除</div>
    <div class="menu-sep"></div>
    <div onClick="print()" data-options="iconCls:'icon-print'">打印</div>
    <div onClick="reload()" data-options="iconCls:'icon-reload'">刷新</div>
</div>

javascript:

//添加右击菜单内容
function onRowContextMenu(e, rowIndex, rowData){
   e.preventDefault();
    var selected=$("#test").datagrid('getRows'); //获取所有行集合对象
     var idValue = selected[rowIndex].id;
     $(this).datagrid('selectRecord', idValue);  //通过获取到的id的值做参数选中一行
    $('#mm').menu('show', {
        left:e.pageX,
        top:e.pageY
    });       
}
//查看详细
function view(){
/***
就是这里获取单行数据方法???? 
treeGrid上倒是很好实现:
  var node = $('#datagrid').treegrid('getSelected');
  if(node){
    ........
  }
***/
}

 

posted on 2014-11-14 11:31  大有@  阅读(350)  评论(0编辑  收藏  举报

导航