博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
datagrid增加提示功能tooltip
阅读量:7089 次
发布时间:2019-06-28

本文共 2543 字,大约阅读时间需要 8 分钟。

hot3.png

datagrid初始化中加入提示

onLoadSuccess:function(data){

            if(!data.rows[0].id) {

                $('#tibetanInformationGrid').datagrid('hideColumn','id');

            }

            $(this).datagrid('doCellTip',{'max-width':'300px','delay':500});

        }

增加提示扩展 

$.extend($.fn.datagrid.methods, {

            /**

             * 开打提示功能

             *  {} jq

             *  {} params 提示消息框的样式

             *  {}

             */

            doCellTip: function(jq, params){

                function showTip(data, td, e){

                    if ($(td).text() == "") 

                        return;

                    data.tooltip.text($(td).text()).css({

                        top: (e.pageY + 10) + 'px',

                        left: (e.pageX + 20) + 'px',

                        'z-index': $.fn.window.defaults.zIndex,

                        display: 'block'

                    });

                };

                return jq.each(function(){

                    var grid = $(this);

                    var options = $(this).data('datagrid');

                    if (!options.tooltip) {

                        var panel = grid.datagrid('getPanel').panel('panel');

                        var defaultCls = {

                            'border': '1px solid #333',

                            'padding': '2px',

                            'color': '#333',

                            'background': '#fff',

                            'position': 'absolute',

                            'max-width': '200px',

                            'border-radius' : '4px',

                            '-moz-border-radius' : '4px',

                            '-webkit-border-radius' : '4px',

                            'display': 'none'

                        }

                        var tooltip = $("<div id='celltip'></div>").appendTo('body');

                        tooltip.css($.extend({}, defaultCls, params.cls));

                        options.tooltip = tooltip;

                        panel.find('.datagrid-body').each(function(){

                            var delegateEle = $(this).find('> div.datagrid-body-inner').length ? $(this).find('> div.datagrid-body-inner')[0] : this;

                            $(delegateEle).undelegate('td', 'mouseover').undelegate('td', 'mouseout').undelegate('td', 'mousemove').delegate('td', {

                                'mouseover': function(e){

                                    if (params.delay) {

                                        if (options.tipDelayTime) 

                                            clearTimeout(options.tipDelayTime);

                                        var that = this;

                                        options.tipDelayTime = setTimeout(function(){

                                            showTip(options, that, e);

                                        }, params.delay);

                                    }

                                    else {

                                        showTip(options, this, e);

                                    }

 

                                },

                                'mouseout': function(e){

                                    if (options.tipDelayTime) 

                                        clearTimeout(options.tipDelayTime);

                                    options.tooltip.css({

                                        'display': 'none'

                                    });

                                },

                                'mousemove': function(e){

                                    var that = this;

                                    if (options.tipDelayTime) 

                                        clearTimeout(options.tipDelayTime);

                                    //showTip(options, this, e);

                                    options.tipDelayTime = setTimeout(function(){

                                            showTip(options, that, e);

                                        }, params.delay);

                                }

                            });

                        });

 

                    }

 

                });

            },

            /**

             * 关闭消息提示功能

             *

             *  {}

             *            jq

             *  {}

             */

            cancelCellTip: function(jq){

                return jq.each(function(){

                    var data = $(this).data('datagrid');

                    if (data.tooltip) {

                        data.tooltip.remove();

                        data.tooltip = null;

                        var panel = $(this).datagrid('getPanel').panel('panel');

                        panel.find('.datagrid-body').undelegate('td', 'mouseover').undelegate('td', 'mouseout').undelegate('td', 'mousemove')

                    }

                    if (data.tipDelayTime) {

                        clearTimeout(data.tipDelayTime);

                        data.tipDelayTime = null;

                    }

                });

            }

        });

 

转载于:https://my.oschina.net/u/1783074/blog/714451

你可能感兴趣的文章
使用 lsof 查找打开的文件
查看>>
Linkwedo 提升信息在决策中的力量
查看>>
雨林木风GhostXP_SP3装机版YN11.6_2011.06更新
查看>>
我的友情链接
查看>>
vim8.0 不能用鼠标
查看>>
OpenGL进阶(十) - obj文件的导入
查看>>
剑指XX游戏(八) - 腾讯2013校园招聘技术类笔试题详解
查看>>
docker 添加基础命令
查看>>
arm7上搭建boa并进行测试cgi+html
查看>>
iptables/netfiles基本使用
查看>>
angularJS拍照
查看>>
HTML5接入与OC交互
查看>>
错误整理:No plugin found for prefix 'jetty' in the....
查看>>
端口号简介
查看>>
JCreator中不能引入servlet包的解决办法
查看>>
mysql root账户被删除
查看>>
将CentOS设置为用光盘做yum源
查看>>
终于用上了比较完美的lion 10.7.3
查看>>
【CentOS 7笔记47】,rsync文件同步工具#171205
查看>>
word2007设置标题自动编号
查看>>