easyui 鼠标移上去显示数据

本文介绍了如何使用EasyUI实现鼠标悬停时显示数据提示的两种方法:一是针对特定字段显示提示,二是使整个Datagrid生效,详细展示了实现效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

      今天写了一个功能,就是把鼠标放上去给个提示,用的是easyui 写的。也找了很多资料,以下是我总结的几种方法:

1.只针对某一个字段进行提示

{
     field:'SUPPLIER_NAME',
     title:'收款单位',
     width:$docWidth*0.20,
     align:'center',
     formatter:function(value,row){   //指定行显示tip
  var text= '<span title="' + value + '" class="tip">' + value + '</span>';  
return text;
}

这种是只对这一行进行提示,其他行则无效果。

2.对整个datagrid有效果

 $.extend($.fn.datagrid.methods, {
                /**
                 * 开打提示功能(基于1.3.3+版本)
                 * @param {} jq
                 * @param {} params 提示消息框的样式
                 * @return {}
                 */
                doCellTip:function (jq, params) {
                    function showTip(showParams, td, e, dg) {
                        //无文本,不提示。
                        if ($(td).text() == "") return;
                        params = params || {};
                        var options = dg.data('datagrid');
                        var styler = 'style="';
                        if(showParams.width){
                            styler = styler + "width:" + showParams.width + ";";
                        }
                        if(showParams.maxWidth){
                            styler = styler + "max-width:" + showParams.maxWidth + ";";
                        }
                        if(showParams.minWidth){
                            styler = styler + "min-width:" + showParams.minWidth + ";";
                        }
                        styler = styler + '"';
                        showParams.content = '<div class="tipcontent" ' + styler + '>' + showParams.content + '</div>';
                        $(td).tooltip({
                            content:showParams.content,
                            trackMouse:true,
                            position:params.position,
                            onHide:function () {
                                $(this).tooltip('destroy');
                            },
                            onShow:function () {
                                var tip = $(this).tooltip('tip');
                                if(showParams.tipStyler){
                                    tip.css(showParams.tipStyler);
                                }
                                if(showParams.contentStyler){
                                    tip.find('div.tipcontent').css(showParams.contentStyler);
                                }
                            }
                        }).tooltip('show');
                    };
                    return jq.each(function () {
                        var grid = $(this);
                        var options = $(this).data('datagrid');
                        if (!options.tooltip) {
                            var panel = grid.datagrid('getPanel').panel('panel');
                            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[field]', {
                                    'mouseover':function (e) {
                                        //if($(this).attr('field')===undefined) return;
                                        var that = this;
                                        var setField = null;
                                        if(params.specialShowFields && params.specialShowFields.sort){
                                            for(var i=0; i<params.specialShowFields.length; i++){
                                                if(params.specialShowFields[i].field == $(this).attr('field')){
                                                    setField = params.specialShowFields[i];
                                                }
                                            }
                                        }
                                        if(setField==null){
                                            options.factContent = $(this).find('>div').clone().css({'margin-left':'-5000px', 'width':'auto', 'display':'inline', 'position':'absolute'}).appendTo('body');
                                            var factContentWidth = options.factContent.width();
                                            params.content = $(this).text();
                                            if (params.onlyShowInterrupt) {
                                                if (factContentWidth > $(this).width()) {
                                                    //showTip(params, this, e, grid);
                                                }
                                            } else {
                                                //showTip(params, this, e, grid);
                                            }
                                        }else{
                                            panel.find('.datagrid-body').each(function(){
                                                var trs = $(this).find('tr[datagrid-row-index="' + $(that).parent().attr('datagrid-row-index') + '"]');
                                                trs.each(function(){
                                                    var td = $(this).find('> td[field="AUDIT_MSG"]');//指定哪列
                                                    if(td.length){//这里是你对数据的处理,如果数据比较长进行换行操作等
                                                        var arry=td.text();
                                                        var arr=arry.split('|');
                                                        var text = "";
                                                        for(var i=0;i<arr.length;i++){
                                                            if (i >0 && i < arr.length) {
                                                                text += '</br>';
                                                            } 
                                                            text += arr[i]; //获取这行所有提交数据
                                                        }
                                                        params.content = text;
                                                    }
                                                });
                                            });
                                            showTip(params, this, e, grid);
                                        }
                                    },
                                    'mouseout':function (e) {
                                        if (options.factContent) {
                                            options.factContent.remove();
                                            options.factContent = null;
                                        }
                                    }
                                });
                            });
                        }
                    });
                },
                /**
                 * 关闭消息提示功能(基于1.3.3版本)
                 * @param {} jq
                 * @return {}
                 */
                cancelCellTip:function (jq) {
                    return jq.each(function () {
                        var data = $(this).data('datagrid');
                        if (data.factContent) {
                            data.factContent.remove();
                            data.factContent = null;
                        }
                        var panel = $(this).datagrid('getPanel').panel('panel');
                        panel.find('.datagrid-body').undelegate('td', 'mouseover').undelegate('td', 'mouseout').undelegate('td', 'mousemove')
                    });
                }
            }); function doCellTips(onlyShowInterrupt) {
        $('#purchaseAppliesGrid').datagrid('doCellTip', {
            onlyShowInterrupt : onlyShowInterrupt,
            position : 'bottom',
            maxWidth : '350px',
            specialShowFields : [ {
                field : 'INDENT_ID',//指定鼠标移到哪个字段上去
                showField : 'INDENT_ID'
            } ],
            tipStyler : {
                'backgroundColor' : '#fff000',
                borderColor : '#ff0000',
                boxShadow : '1px 1px 3px #292929'
            }
        });
    }

效果显示如下:


这样就把可以把要显示的都显示出来了。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值