$.extend($.fn.datagrid.methods, { /** * 开打提示功能 * @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'); showparams.content = '
' + showparams.content + '
'; $(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="' + setfield.showfield + '"]'); if (td.length) { params.content = td.text(); } }); }); showtip(params, this, e, grid); } }, 'mouseout': function (e) { if (options.factcontent) { options.factcontent.remove(); options.factcontent = null; } } }); }); } }); }, /** * 关闭消息提示功能 * @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') }); } });