此文章是基于  EasyUI+Knockout实现经典表单的查看、编辑

一. jquery.cellTip.js

  1. /**
  2. * 扩展两个方法
  3. */
  4. using('datagrid', function(){
  5. $.extend($.fn.datagrid.methods, {
  6. /**
  7. * 开打提示功能
  8. * @param {} jq
  9. * @param {} params 提示消息框的样式
  10. * @return {}
  11. */
  12. doCellTip: function(jq, params){
  13. function showTip(data, td, e){
  14. if ($(td).text() == "")
  15. return;
  16. data.tooltip.text($(td).text()).css({
  17. top: (e.pageY + 10) + 'px',
  18. left: (e.pageX + 20) + 'px',
  19. 'z-index': $.fn.window.defaults.zIndex,
  20. display: 'block'
  21. });
  22. };
  23. return jq.each(function(){
  24. var grid = $(this);
  25. var options = $(this).data('datagrid');
  26. if (!options.tooltip) {
  27. var panel = grid.datagrid('getPanel').panel('panel');
  28. var defaultCls = {
  29. 'border': '1px solid #333',
  30. 'padding': '2px',
  31. 'color': '#333',
  32. 'background': '#f7f5d1',
  33. 'position': 'absolute',
  34. 'max-width': '200px',
  35. 'border-radius' : '4px',
  36. '-moz-border-radius' : '4px',
  37. '-webkit-border-radius' : '4px',
  38. 'display': 'none'
  39. }
  40. var tooltip = $("<div id='celltip'></div>").appendTo('body');
  41. tooltip.css($.extend({}, defaultCls, params.cls));
  42. options.tooltip = tooltip;
  43. panel.find('.datagrid-body').each(function(){
  44. var delegateEle = $(this).find('> div.datagrid-body-inner').length ? $(this).find('> div.datagrid-body-inner')[0] : this;
  45. $(delegateEle).find('td').each(function(i){
  46. var ele = $(this).parent();
  47. // 适用于treegrid
  48. if($(this).find('td').length > 0)
  49. ele = $(this);
  50. $(ele).undelegate('td', 'mouseover').undelegate('td', 'mouseout').undelegate('td', 'mousemove').delegate('td', {
  51. 'mouseover': function(e){
  52. if (params.delay) {
  53. if (options.tipDelayTime)
  54. clearTimeout(options.tipDelayTime);
  55. var that = this;
  56. options.tipDelayTime = setTimeout(function(){
  57. showTip(options, that, e);
  58. }, params.delay);
  59. }
  60. else {
  61. showTip(options, this, e);
  62. }
  63.  
  64. },
  65. 'mouseout': function(e){
  66. if (options.tipDelayTime)
  67. clearTimeout(options.tipDelayTime);
  68. options.tooltip.css({
  69. 'display': 'none'
  70. });
  71. },
  72. 'mousemove': function(e){
  73. var that = this;
  74. if (options.tipDelayTime)
  75. clearTimeout(options.tipDelayTime);
  76. //showTip(options, this, e);
  77. options.tipDelayTime = setTimeout(function(){
  78. showTip(options, that, e);
  79. }, params.delay);
  80. }
  81. });
  82. });
  83.  
  84. });
  85.  
  86. }
  87.  
  88. });
  89. },
  90. /**
  91. * 关闭消息提示功能
  92. *
  93. * @param {}
  94. * jq
  95. * @return {}
  96. */
  97. cancelCellTip: function(jq){
  98. return jq.each(function(){
  99. var data = $(this).data('datagrid');
  100. if (data.tooltip) {
  101. data.tooltip.remove();
  102. data.tooltip = null;
  103. var panel = $(this).datagrid('getPanel').panel('panel');
  104. panel.find('.datagrid-body').undelegate('td', 'mouseover').undelegate('td', 'mouseout').undelegate('td', 'mousemove')
  105. }
  106. if (data.tipDelayTime) {
  107. clearTimeout(data.tipDelayTime);
  108. data.tipDelayTime = null;
  109. }
  110. });
  111. }
  112. });
  113. });

二. 测试页面

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
  2. <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
  3. <html>
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  6. <title>datagrid鼠标经过提示单元格内容</title>
  7. <%@ include file="/common/head.jsp"%>
  8. </head>
  9. <body>
  10. <div style="margin:10px 0;">
  11. <a href="#" onclick="doCellTip()">显示提示消息</a>
  12. <a href="#" onclick="cancelCellTip()">禁止消息显示</a>
  13. <div id="info"></div>
  14. </div>
  15.  
  16. <table id="test" class="easyui-datagrid" style="width:100%;height:520px;" data-options="fitColumns:true, singleSelect:true, rownumbers:true">
  17. <thead>
  18. <tr>
  19. <th data-options="field:'direction', width:150, align:'center'">direction</th>
  20. </tr>
  21. </thead>
  22. </table>
  23.  
  24. <%@ include file="/common/foot.jsp"%>
  25. <script type="text/javascript" src="content/js/jquery-plugin/cellTip/jquery.cellTip.js"></script>
  26. <script type="text/javascript">
  27. function doCellTip(){
  28. $('#test').datagrid('doCellTip', {'cls':{'max-width':'200px'}});
  29. }
  30. function cancelCellTip(){
  31. $('#test').datagrid('cancelCellTip');
  32. }
  33.  
  34. $(function(){
  35. var data = ${data};
  36. ko.bindingViewModel(new viewModel(data));
  37. });
  38. using(['messager', 'datagrid'], function(){
  39. $('#test').datagrid({
  40. onLoadSuccess: function(data){
  41. $(this).datagrid('doCellTip', {'cls':{'max-width':'600px'}, 'delay':500});
  42. }
  43. });
  44. });
  45. </script>
  46. </body>
  47. </html>

testGrid.jsp

easyUi datagrid鼠标经过提示单元格内容的更多相关文章

  1. EasyUI Datagrid 鼠标悬停显示单元格内容 复制代码

    EasyUI Datagrid 鼠标悬停显示单元格内容 ,halign:, align: 0 « 上一篇:LINQ to Entities 中的查询» 下一篇:去掉字符串中的非数字字符 posted ...

  2. EasyUI Datagrid 鼠标悬停显示单元格内容

    第一种方式: .js 定义函数 <script type="text/javascript"> //格式化单元格提示信息 function formatCellTool ...

  3. EasyUI的Datagrid鼠标悬停显示单元格内容

    功能描述:table鼠标悬停显示单元格内容 1.js函数 function hoveringShow(value) { return "<span title='" + va ...

  4. VC/MFC 在ListCtl 控件中随鼠标移动提示单元格信息

    BEGIN_MESSAGE_MAP(CTipListCtrl, CListCtrl) //{{AFX_MSG_MAP(CTipListCtrl) ON_WM_MOUSEMOVE() ON_WM_DES ...

  5. EasyUI datagrid单元格文本超出显示省略号,鼠标移动到单元格显示文本

    nowrap : true;  是前提 $('#×××').datagrid({ nowrap : true,//设置为true,当数据长度超出列宽时将会自动截取 }); 省略号样式: <sty ...

  6. 获取wpf datagrid当前被编辑单元格的内容

    原文 获取wpf datagrid当前被编辑单元格的内容 确认修改单元个的值, 使用到datagrid的两个事件 开始编辑事件 BeginningEdit="dataGrid_Beginni ...

  7. C# DataGridView在单元格提示里(ToolTip)显示完整的单元格内容

    当单元格内容太多时,则会忽略后面的内容 解决方案: 添加Dgv鼠标移到单元格事件时,设置当前单元格的ToolTipText属性内容为当前单元格内容 void From_Load(object send ...

  8. EXCEL中统计单元格内容出现次数

    参考网站: https://jingyan.baidu.com/article/7c6fb428dfcc9580642c90ae.html 统计单元格内容出现次数是工作中经常会涉及到的问题. 那么,如 ...

  9. 原创:用VBA实现将鼠标选择的单元格按照指定格式合并并复制到剪切板

    原创:用VBA实现将鼠标选择的单元格按照指定格式合并并复制到剪切板 一.主要实现以下功能:1.用鼠标选择单元格(可谓连续单元格,也可为不连续的)后,按照要求格式“证件号码:+选定内容+“,”+”选定内 ...

随机推荐

  1. PHP7 - 如何禁用Xdebug

    操作系统:Cent OS 7 什么是Xdebug?看它的官方网站介绍: https://xdebug.org/index.php 为什么要禁用呢?这是因为Composer,这两种工具有冲突,在使用Co ...

  2. 978. Longest Turbulent Subarray

    A subarray A[i], A[i+1], ..., A[j] of A is said to be turbulent if and only if: For i <= k < j ...

  3. 内核漏洞学习—熟悉HEVD

    一直以来内核漏洞安全给很多人的印象就是:难,枯燥.但是内核安全是否掌握是衡量一个系统安全工程师水平的标准之一,也是安全从业人员都应该掌握的基本功.本文通过详细的实例带领读者走进内核安全的大门.难度系数 ...

  4. 使用Dockerfile定制镜像

    Dockerfile是一个文本文件,其中包含额一条一条的指令,每一条指令构建一层,因此每一条指令的作用就是描述这一层应当如何的构建. 以构建nginx镜像为例,使用Dockerfile构建的步骤如下: ...

  5. Netty核心概念(8)之Netty线程模型

    1.前言 第7节初步学习了一下Java原本的线程池是如何工作的,以及Future的为什么能够达到其效果,这些知识对于理解本章有很大的帮助,不了解的可以先看上一节. Netty为什么会高效?回答就是良好 ...

  6. Java之集合(二十)LinkedBlockingQueue

    转载请注明源出处:http://www.cnblogs.com/lighten/p/7503678.html 1.前言 本章介绍阻塞队列LinkedBlockingQueue,这是一个基于链表的可选长 ...

  7. 【树】Sum Root to Leaf Numbers

    题目: Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a nu ...

  8. win10下用Linux搭建python&nodejs开发环境

    Win10下用自带Linux系统搭建开发环境 Win10下用自带Linux系统搭建开发环境启用Linux老版本(win10 1709之前):新版本(win10 1709之后)卸载linux老版本新版本 ...

  9. Centos调整时间时区

    一台VPS的时间出错,使用常规手段修改均失败.提示hwclock failed : ntpdate stdtime.sinica.edu.tw 如果你的 VPS 提示没有 ntpdate 这个命令,可 ...

  10. 09 - JavaSE之线程

    线程 线程的基本概念 线程是一个程序里面不同的执行路径. 进程与线程的区别 每个进程都有独立的代码和数据空间(进程上下文),进程间的切换开销大. 线程可以看作轻量级的进程,同一类线程共享代码和数据空间 ...