效果图如下
js代码:
// Create the namespace Ext.ns('Ext.ux.plugins.grid'); /** * Ext.ux.plugins.grid.CellToolTips plugin for Ext.grid.GridPanel * * A GridPanel plugin that enables the creation of record based, * per-column tooltips that can also be dynamically loaded via Ajax * calls. * * Requires Animal's triggerElement override when using ExtJS 2.x * (from <a href="http://extjs.com/forum/showthread.php?p=265259#post265259" mce_href="http://extjs.com/forum/showthread.php?p=265259#post265259">http://extjs.com/forum/showthread.php?p=265259#post265259</a>) * In ExtJS 3.0 this feature is arealy in the standard. * * @author BitPoet * @date July 03, 2009 * @version 1.1 * * @class Ext.ux.plugins.grid.CellToolTips * @extends Ext.util.Observable */ /** * Constructor for the Plugin * * @param {ConfigObject} config * @constructor */ Ext.ux.plugins.grid.CellToolTips = function(config) { var cfgTips; if( Ext.isArray(config) ) { cfgTips = config; config = {}; } else { cfgTips = config.ajaxTips; } Ext.ux.plugins.grid.CellToolTips.superclass.constructor.call(this, config); if( config.tipConfig ) { this.tipConfig = config.tipConfig; } this.ajaxTips = cfgTips; } // End of constructor // plugin code Ext.extend( Ext.ux.plugins.grid.CellToolTips, Ext.util.Observable, { version: 1.1, /** * Temp storage from the config object * * @private */ ajaxTips: false, /** * Tooltip Templates indexed by column id * * @private */ tipTpls: false, /** * Tooltip data filter function for setting base parameters * * @private */ tipFns: false, /** * URLs for ajax backend * * @private */ tipUrls: '', /** * Tooltip configuration items * * @private */ tipConfig: {}, /** * Loading action * * @private */ request: false, /** * Plugin initialization routine * * @param {Ext.grid.GridPanel} grid */ init: function(grid) { if( ! this.ajaxTips ) { return; } this.tipTpls = {}; this.tipFns = {}; this.tipUrls = {}; // Generate tooltip templates Ext.each( this.ajaxTips, function(tip) { this.tipTpls[tip.field] = new Ext.XTemplate( tip.tpl ); if( tip.url ) { this.tipUrls[tip.field] = tip.url; if( tip.fn ) this.tipFns[tip.field] = tip.fn; } }, this); // delete now superfluous config entry for ajaxTips delete( this.ajaxTips ); grid.on( 'render', this.onGridRender.createDelegate(this) ); } // End of function init /** * Set/Add a template for a column * * @param {String} fld * @param {String | Ext.XTemplate} tpl */ ,setFieldTpl: function(fld, tpl) { this.tipTpls[fld] = Ext.isObject(tpl) ? tpl : new Ext.XTemplate(tpl); } // End of function setFieldTpl /** * Set up the tooltip when the grid is rendered * * @private * @param {Ext.grid.GridPanel} grid */ ,onGridRender: function(grid) { if( ! this.tipTpls ) { return; } // Create one new tooltip for the whole grid Ext.apply(this.tipConfig, { target: grid.getView().mainBody, delegate: '.x-grid3-cell-inner', trackMouse: true, renderTo: document.body, finished: false }); this.tip = new Ext.ToolTip( this.tipConfig ); this.tip.ctt = this; // Hook onto the beforeshow event to update the tooltip content this.tip.on('beforeshow', this.beforeTipShow.createDelegate(this.tip, [this, grid], true)); this.tip.on('hide', this.hideTip); } // End of function onGridRender /** * Replace the tooltip body by applying current row data to the template * * @private * @param {Ext.ToolTip} tip * @param {Ext.ux.plugins.grid.CellToolTips} ctt * @param {Ext.grid.GridPanel} grid */ ,beforeTipShow: function(tip, ctt, grid) { // Get column id and check if a tip is defined for it var colIdx = grid.getView().findCellIndex( tip.triggerElement ); var tipId = grid.getColumnModel().getDataIndex( colIdx ); if( ! ctt.tipTpls[tipId] ) return false; if( ! tip.finished ) { var isAjaxTip = (typeof ctt.tipUrls[tipId] == 'string'); // Fetch the row's record from the store and apply the template var cellRec = grid.getStore().getAt( grid.getView().findRowIndex( tip.triggerElement ) ); // create a copy of the record and use its data, otherwise we might // accidentially modify the original record's values var data = cellRec.copy().data; if( isAjaxTip ) { ctt.loadDetails((ctt.tipFns[tipId]) ? ctt.tipFns[tipId](data) : data, tip, grid, ctt, tipId); return false; } else { tip.body.dom.innerHTML = ctt.tipTpls[tipId].apply( cellRec.data ); } } else { tip.body.dom.innerHTML = tip.ctt.tipTpls[tipId].apply( tip.tipdata ); } } // End of function beforeTipShow /** * Fired when the tooltip is hidden, resets the finished handler. * * @private * @param {Ext.ToolTip} tip */ ,hideTip: function(tip) { tip.finished = false; } /** * Loads the data to apply to the tip template via Ajax * * @private * @param {object} data Parameters for the Ajax request * @param {Ext.ToolTip} tip The tooltip object * @param {Ext.grid.GridPanel} grid The grid * @param {Ext.ux.plugins.grid.CellToolTips} ctt The CellToolTips object * @param {String} tipid Id of the tooltip (= field name) */ ,loadDetails: function(data, tip, grid, ctt, tipid) { Ext.Ajax.request({ url: ctt.tipUrls[tipid], params: data, method: 'POST', success: function(resp, opt) { tip.finished = true; tip.tipdata = Ext.decode(resp.responseText); tip.show(); } }); } }); // End of extend
//当鼠标滑到项目名称,计划字段的时候(LogText),显示任务内容的详细信息 /* http://www.sencha.com/forum/showthread.php?59895-Ext.ux.plugins.grid.CellToolTips&highlight=Extjs+grid+Tip */ var cellTips = new Ext.ux.plugins.grid.CellToolTips ( [ { field: 'ProjectName', tpl: '<b>项目名称</b>:{ProjectName}<br/>责任人:{LiabilityMan}<br/>计划完成时间:{LogDate}<br/>任务内容: {Remark}' }, { field: 'LogText', tpl: '<b>项目名称</b>:{ProjectName}<br/>责任人:{LiabilityMan}<br/>计划完成时间:{LogDate}<br/>任务内容: {Remark}' } ] );
Grid中添加插件
var grid = new Ext.grid.GridPanel ({ id: "MenuGridPanel", title: '任务列表', renderTo:"d", layout: "fit", width: "100%", autoHeight: true, frame: true, border: true, columnLines: true, autoScroll: true, loadMask: {msg:'正在加载数据,请稍侯……'}, store: store, sm: sm, cm: cm, plugins: [ cellTips ]//这是这个代码 ... })
您还没有登录,请您登录后再发表评论
Extjs4的textfield控件竟然没有tooltip悬浮提示,这应该算是个bug吧。网上查了很多,也没有方案。后来自己通过查询并整理出这个方案,终于实现了。 思想如下: 在textfield渲染时注册mouseover事件,然后在其中调用...
ExtJS grid过滤操作,可以动态操作本地的store更改筛选的内容
extjs grid示例代码extjs grid示例代码extjs grid示例代码extjs grid示例代码
ExtJS tooltip功能组件实例
ExtJs Grid是否选择行,是:返回选择行record;否:返回false
Extjs grid 中文排序问题修正,其实很简单,请自己看源代码
EXTJS grid导出EXCEL文件,源码可以直接导入MYECLIPSE使用,EXTJS版本3.2.0
extjs grid 多表头 插件 extjs grid 多表头 插件
这是利用sencha cmd 生成的GridFilterDemo工程中的app和build文件夹,其余文件过大并且与主题无关,因此未包含。具体方法,请参看我的博客: 《Extjs4.2 Grid Filter Feature 表格过滤特性》
extjs grid ide:myeclipse5.5 jboss4.2.1 extjs4.2.1
很多同事在用extjs grid做分页的时候,往往会想用grid的多选功能来实现导出Excel之类的功能(也就是所谓的多选记忆功能),但在选选择下一页的时候 上一页选中的已经清除 这是因为做分页的时候又向服务器请求了分页...
ExtJs 4.0 Grid 单元格合并控件封装
ExtJs grid多选时获取选中的所有值,以及其他相关的操作
这是一个简单的在extjs下的grid转化到Excel,里面代码简单易懂,在包里面还集成了复杂的js转化函数,不过本人没有用它来进行转化! 注:在用EXTJS的导出Excel技术中,一定要注意分页的问题
Extjs 中想改变grid 行高,如果只是简单的设置了height的值是可以实现grid 的行高,但是如果使用了插件:rowexpander ,最出现新的问题。 感兴趣的朋友可以试试的。 此文档可以解决你的烦恼,为了找到资源下载,...
自己写的一个Extjs Grid2Grid拖拽
Extjs动态Grid的生成 htm
EXTJS Grid布局总结例子,含源代码。
相关推荐
Extjs4的textfield控件竟然没有tooltip悬浮提示,这应该算是个bug吧。网上查了很多,也没有方案。后来自己通过查询并整理出这个方案,终于实现了。 思想如下: 在textfield渲染时注册mouseover事件,然后在其中调用...
ExtJS grid过滤操作,可以动态操作本地的store更改筛选的内容
extjs grid示例代码extjs grid示例代码extjs grid示例代码extjs grid示例代码
ExtJS tooltip功能组件实例
ExtJs Grid是否选择行,是:返回选择行record;否:返回false
Extjs grid 中文排序问题修正,其实很简单,请自己看源代码
EXTJS grid导出EXCEL文件,源码可以直接导入MYECLIPSE使用,EXTJS版本3.2.0
extjs grid 多表头 插件 extjs grid 多表头 插件
这是利用sencha cmd 生成的GridFilterDemo工程中的app和build文件夹,其余文件过大并且与主题无关,因此未包含。具体方法,请参看我的博客: 《Extjs4.2 Grid Filter Feature 表格过滤特性》
extjs grid ide:myeclipse5.5 jboss4.2.1 extjs4.2.1
很多同事在用extjs grid做分页的时候,往往会想用grid的多选功能来实现导出Excel之类的功能(也就是所谓的多选记忆功能),但在选选择下一页的时候 上一页选中的已经清除 这是因为做分页的时候又向服务器请求了分页...
ExtJs 4.0 Grid 单元格合并控件封装
ExtJs grid多选时获取选中的所有值,以及其他相关的操作
这是一个简单的在extjs下的grid转化到Excel,里面代码简单易懂,在包里面还集成了复杂的js转化函数,不过本人没有用它来进行转化! 注:在用EXTJS的导出Excel技术中,一定要注意分页的问题
Extjs 中想改变grid 行高,如果只是简单的设置了height的值是可以实现grid 的行高,但是如果使用了插件:rowexpander ,最出现新的问题。 感兴趣的朋友可以试试的。 此文档可以解决你的烦恼,为了找到资源下载,...
自己写的一个Extjs Grid2Grid拖拽
Extjs动态Grid的生成 htm
EXTJS Grid布局总结例子,含源代码。