easyui拓展title

  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4.     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
  5.     <title>Complex DataGrid - 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-1.8.0.min.js"></script>  
  10.     <script type="text/javascript" src="../../jquery.easyui.min.js"></script>  
  11.     <script>  
  12.         /**  
  13.          * 扩展两个方法  
  14.          */  
  15.         $.extend($.fn.datagrid.methods, {  
  16.             /**  
  17.              * 开打提示功能  
  18.              * @param {} jq  
  19.              * @param {} params 提示消息框的样式  
  20.              * @return {}  
  21.              */  
  22.             doCellTip: function(jq, params){  
  23.                 function showTip(data, td, e){  
  24.                     if ($(td).text() == "")   
  25.                         return;  
  26.                     data.tooltip.text($(td).text()).css({  
  27.                         top: (e.pageY + 10) + 'px',  
  28.                         left: (e.pageX + 20) + 'px',  
  29.                         'z-index': $.fn.window.defaults.zIndex,  
  30.                         display: 'block'  
  31.                     });  
  32.                 };  
  33.                 return jq.each(function(){  
  34.                     var grid = $(this);  
  35.                     var options = $(this).data('datagrid');  
  36.                     if (!options.tooltip) {  
  37.                         var panel = grid.datagrid('getPanel').panel('panel');  
  38.                         var defaultCls = {  
  39.                             'border': '1px solid #333',  
  40.                             'padding': '2px',  
  41.                             'color': '#333',  
  42.                             'background': '#f7f5d1',  
  43.                             'position': 'absolute',  
  44.                             'max-width': '200px',  
  45.                             'border-radius' : '4px',  
  46.                             '-moz-border-radius' : '4px',  
  47.                             '-webkit-border-radius' : '4px',  
  48.                             'display': 'none'  
  49.                         }  
  50.                         var tooltip = $("<div id='celltip'></div>").appendTo('body');  
  51.                         tooltip.css($.extend({}, defaultCls, params.cls));  
  52.                         options.tooltip = tooltip;  
  53.                         panel.find('.datagrid-body').each(function(){  
  54.                             var delegateEle = $(this).find('> div.datagrid-body-inner').length ? $(this).find('> div.datagrid-body-inner')[0] : this;  
  55.                             $(delegateEle).undelegate('td', 'mouseover').undelegate('td', 'mouseout').undelegate('td', 'mousemove').delegate('td', {  
  56.                                 'mouseover': function(e){  
  57.                                     if (params.delay) {  
  58.                                         if (options.tipDelayTime)   
  59.                                             clearTimeout(options.tipDelayTime);  
  60.                                         var that = this;  
  61.                                         options.tipDelayTime = setTimeout(function(){  
  62.                                             showTip(options, that, e);  
  63.                                         }, params.delay);  
  64.                                     }  
  65.                                     else {  
  66.                                         showTip(options, this, e);  
  67.                                     }  
  68.                                       
  69.                                 },  
  70.                                 'mouseout': function(e){  
  71.                                     if (options.tipDelayTime)   
  72.                                         clearTimeout(options.tipDelayTime);  
  73.                                     options.tooltip.css({  
  74.                                         'display': 'none'  
  75.                                     });  
  76.                                 },  
  77.                                 'mousemove': function(e){  
  78.                                     var that = this;  
  79.                                     if (options.tipDelayTime)   
  80.                                         clearTimeout(options.tipDelayTime);  
  81.                                     //showTip(options, this, e);  
  82.                                     options.tipDelayTime = setTimeout(function(){  
  83.                                             showTip(options, that, e);  
  84.                                         }, params.delay);  
  85.                                 }  
  86.                             });  
  87.                         });  
  88.                           
  89.                     }  
  90.                       
  91.                 });  
  92.             },  
  93.             /**  
  94.              * 关闭消息提示功能  
  95.              *  
  96.              * @param {}  
  97.              *            jq  
  98.              * @return {}  
  99.              */  
  100.             cancelCellTip: function(jq){  
  101.                 return jq.each(function(){  
  102.                     var data = $(this).data('datagrid');  
  103.                     if (data.tooltip) {  
  104.                         data.tooltip.remove();  
  105.                         data.tooltip = null;  
  106.                         var panel = $(this).datagrid('getPanel').panel('panel');  
  107.                         panel.find('.datagrid-body').undelegate('td', 'mouseover').undelegate('td', 'mouseout').undelegate('td', 'mousemove')  
  108.                     }  
  109.                     if (data.tipDelayTime) {  
  110.                         clearTimeout(data.tipDelayTime);  
  111.                         data.tipDelayTime = null;  
  112.                     }  
  113.                 });  
  114.             }  
  115.         });  
  116.   
  117.         $(function(){  
  118.             $('#test').datagrid({  
  119.                 title:'My DataGrid',  
  120.                 iconCls:'icon-save',  
  121.                 width:700,  
  122.                 height:350,  
  123.                 nowrap: true,  
  124.                 autoRowHeight: false,  
  125.                 striped: true,  
  126.                 collapsible:true,  
  127.                 url:'066.json',  
  128.                 sortName: 'code',  
  129.                 sortOrder: 'desc',  
  130.                 remoteSort: false,  
  131.                 idField:'code',  
  132.                 onLoadSuccess:function(data){  
  133.                     $(this).datagrid('doCellTip',{'max-width':'300px','delay':500});  
  134.                 },  
  135.                 frozenColumns:[[  
  136.                     {field:'ck',checkbox:true},  
  137.                     {title:'Code',field:'code',width:80,sortable:true}  
  138.                 ]],  
  139.                 columns:[[  
  140.                     {title:'Base Information',colspan:3},  
  141.                     {field:'opt',title:'Operation',width:100,align:'center', rowspan:2,  
  142.                         formatter:function(value,rec){  
  143.                             return '<span style="color:red">Edit Delete</span>';  
  144.                         }  
  145.                     }  
  146.                 ],[  
  147.                     {field:'name',title:'Name',width:120},  
  148.                     {field:'addr',title:'Address',width:220,rowspan:2,sortable:true,  
  149.                         sorter:function(a,b){  
  150.                             return (a>b?1:-1);  
  151.                         }  
  152.                     },  
  153.                     {field:'col4',title:'Col41',width:150,rowspan:2}  
  154.                 ]],  
  155.                 pagination:true,  
  156.                 rownumbers:true,  
  157.                 toolbar:[{  
  158.                     id:'btnadd',  
  159.                     text:'Add',  
  160.                     iconCls:'icon-add',  
  161.                     handler:function(){  
  162.                         $('#btnsave').linkbutton('enable');  
  163.                         alert('add')  
  164.                     }  
  165.                 },{  
  166.                     id:'btncut',  
  167.                     text:'Cut',  
  168.                     iconCls:'icon-cut',  
  169.                     handler:function(){  
  170.                         $('#btnsave').linkbutton('enable');  
  171.                         alert('cut')  
  172.                     }  
  173.                 },'-',{  
  174.                     id:'btnsave',  
  175.                     text:'Save',  
  176.                     disabled:true,  
  177.                     iconCls:'icon-save',  
  178.                     handler:function(){  
  179.                         $('#btnsave').linkbutton('disable');  
  180.                         alert('save')  
  181.                     }  
  182.                 }]  
  183.             });  
  184.             var p = $('#test').datagrid('getPager');  
  185.             $(p).pagination({  
  186.                 onBeforeRefresh:function(){  
  187.                     alert('before refresh');  
  188.                 }  
  189.             });  
  190.         });  
  191.         function doCellTip(){  
  192.             $('#test').datagrid('doCellTip',{'max-width':'100px'});  
  193.         }  
  194.         function cancelCellTip(){  
  195.             $('#test').datagrid('cancelCellTip');  
  196.         }  
  197.           
  198.     </script>  
  199. </head>  
  200. <body>  
  201.     <h2>Complex DataGrid</h2>  
  202.     <div class="demo-info">  
  203.         <div class="demo-tip icon-tip"></div>  
  204.         <div>Click the button to do actions with datagrid. </div>  
  205.     </div>  
  206.       
  207.     <div style="margin:10px 0;">  
  208.         <a href="#" onclick="doCellTip()">显示提示消息</a>  
  209.         <a href="#" onclick="cancelCellTip()">禁止消息显示</a>  
  210.         <div id="info"></div>  
  211.     </div>  
  212.     <table id="test"></table>  
  213. </body>  
  214. </html>  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值