contextmenu.html 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>TreeGrid ContextMenu - jQuery EasyUI Demo</title>
  6. <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css">
  7. <link rel="stylesheet" type="text/css" href="../../themes/icon.css">
  8. <link rel="stylesheet" type="text/css" href="../demo.css">
  9. <script type="text/javascript" src="../../jquery.min.js"></script>
  10. <script type="text/javascript" src="../../jquery.easyui.min.js"></script>
  11. </head>
  12. <body>
  13. <h2>TreeGrid ContextMenu</h2>
  14. <p>Right click to display the context menu.</p>
  15. <div style="margin:20px 0;"></div>
  16. <table id="tg" class="easyui-treegrid" title="TreeGrid ContextMenu" style="width:700px;height:250px"
  17. data-options="
  18. iconCls: 'icon-ok',
  19. rownumbers: true,
  20. animate: true,
  21. collapsible: true,
  22. fitColumns: true,
  23. url: 'treegrid_data2.json',
  24. method: 'get',
  25. idField: 'id',
  26. treeField: 'name',
  27. onContextMenu: onContextMenu
  28. ">
  29. <thead>
  30. <tr>
  31. <th data-options="field:'name',width:180">Task Name</th>
  32. <th data-options="field:'persons',width:60,align:'right'">Persons</th>
  33. <th data-options="field:'begin',width:80">Begin Date</th>
  34. <th data-options="field:'end',width:80">End Date</th>
  35. <th data-options="field:'progress',width:120,formatter:formatProgress">Progress</th>
  36. </tr>
  37. </thead>
  38. </table>
  39. <div id="mm" class="easyui-menu" style="width:120px;">
  40. <div onclick="append()" data-options="iconCls:'icon-add'">Append</div>
  41. <div onclick="removeIt()" data-options="iconCls:'icon-remove'">Remove</div>
  42. <div class="menu-sep"></div>
  43. <div onclick="collapse()">Collapse</div>
  44. <div onclick="expand()">Expand</div>
  45. </div>
  46. <script type="text/javascript">
  47. function formatProgress(value){
  48. if (value){
  49. var s = '<div style="width:100%;border:1px solid #ccc">' +
  50. '<div style="width:' + value + '%;background:#cc0000;color:#fff">' + value + '%' + '</div>'
  51. '</div>';
  52. return s;
  53. } else {
  54. return '';
  55. }
  56. }
  57. function onContextMenu(e,row){
  58. if (row){
  59. e.preventDefault();
  60. $(this).treegrid('select', row.id);
  61. $('#mm').menu('show',{
  62. left: e.pageX,
  63. top: e.pageY
  64. });
  65. }
  66. }
  67. var idIndex = 100;
  68. function append(){
  69. idIndex++;
  70. var d1 = new Date();
  71. var d2 = new Date();
  72. d2.setMonth(d2.getMonth()+1);
  73. var node = $('#tg').treegrid('getSelected');
  74. $('#tg').treegrid('append',{
  75. parent: node.id,
  76. data: [{
  77. id: idIndex,
  78. name: 'New Task'+idIndex,
  79. persons: parseInt(Math.random()*10),
  80. begin: $.fn.datebox.defaults.formatter(d1),
  81. end: $.fn.datebox.defaults.formatter(d2),
  82. progress: parseInt(Math.random()*100)
  83. }]
  84. })
  85. }
  86. function removeIt(){
  87. var node = $('#tg').treegrid('getSelected');
  88. if (node){
  89. $('#tg').treegrid('remove', node.id);
  90. }
  91. }
  92. function collapse(){
  93. var node = $('#tg').treegrid('getSelected');
  94. if (node){
  95. $('#tg').treegrid('collapse', node.id);
  96. }
  97. }
  98. function expand(){
  99. var node = $('#tg').treegrid('getSelected');
  100. if (node){
  101. $('#tg').treegrid('expand', node.id);
  102. }
  103. }
  104. </script>
  105. </body>
  106. </html>