5.Ext JS actioncolumn动态加载图标/提示

16 篇文章 0 订阅

官网介绍

图标加载

getClass : Function  

    A function which returns the CSS class to apply to the icon image.  

    Parameters  
        v : Object  
        The value of the column's configured field (if any).  

        metadata : Object  
        An object in which you may set the following attributes:  

            css : String  
            A CSS class name to add to the cell's TD element.  

            attr : String  
            An HTML attribute definition string to apply to the data container element within the table cell (e.g. 'style="color:red;"').  

        r : Ext.data.Model  
        The Record providing the data.  

        rowIndex : Number  
        The row index.  

        colIndex : Number  
        The column index.  

        store : Ext.data.Store  
        The Store which is providing the data Model.  

提示加载

getTip : Function

A function which returns the tooltip string for any row.
Parameters

    v : Object
    The value of the column's configured field (if any).

    metadata : Object
    An object in which you may set the following attributes:

        css : String
        A CSS class name to add to the cell's TD element.

        attr : String
        An HTML attribute definition string to apply to the data container element within the table cell (e.g. 'style="color:red;"').

    r : Ext.data.Model
    The Record providing the data.

    rowIndex : Number
    The row index.

    colIndex : Number
    The column index.

    store : Ext.data.Store
    The Store which is providing the data Model.


项目实战

text : "操作",
xtype:'actioncolumn',
sortable : false,
width : 190,
items : [{
	handler : "projectFavorite",
	name : 'projectFavorite',
	getClass : function (v, metadata, r, rowIndex, colIndex, store) {
		if (me.userType == '20') {
			if (r.data.partaked){ 
				return "x-item-disabled x-fa fa-heart";
			} else {
				return r.data.favorite == true ? "x-fa fa-heart" : "x-fa fa-heart-o";
			}
		}
	},
	getTip : function (v, metadata, r, rowIndex, colIndex, store) {
		if (me.userType == '20') {
			return r.data.favorite == true ? "取消关注" : "关注";
		}
	}
}]


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您可以通过 `actioncolumn` 类型的列来向表格中添加按钮。这个列类型可以在每一行中添加一个或多个按钮,每个按钮可以触发不同的操作。您可以为每个按钮设置一个处理函数或者使用 `handler` 属性来为所有按钮设置一个共同的处理函数。 下面是一个使用 `actioncolumn` 列类型向表格中添加按钮的例子: ```javascript Ext.require(['Ext.grid.*']); Ext.onReady(function() { // 创建一个简单的数据存储 var store = Ext.create('Ext.data.Store', { fields: ['name', 'email', 'phone'], data: [ { 'name': 'Lisa', "email":"[email protected]", "phone":"555-111-1224" }, { 'name': 'Bart', "email":"[email protected]", "phone":"555-222-1234" }, { 'name': 'Homer', "email":"[email protected]", "phone":"555-222-1244" }, { 'name': 'Marge', "email":"[email protected]", "phone":"555-222-1254" } ] }); // 创建一个表格 var grid = Ext.create('Ext.grid.Panel', { renderTo: Ext.getBody(), store: store, height: 250, width: 500, title: 'Employee Directory', columns: [ { header: 'Name', dataIndex: 'name' }, { header: 'Email', dataIndex: 'email', flex: 1 }, { header: 'Phone', dataIndex: 'phone' }, // 添加一个 actioncolumn 列类型 { xtype: 'actioncolumn', width: 50, items: [{ icon: 'https://cdn3.iconfinder.com/data/icons/faticons/32/refresh-01-512.png', tooltip: 'Click to refresh', handler: function(grid, rowIndex, colIndex) { alert('Refresh button clicked!'); } }] } ] }); }); ``` 这个例子中,我们添加了一个 `actioncolumn` 类型的列,其中包含一个刷新图标的按钮。当用户单击此按钮时,将调用处理函数 `handler`,在这个例子中,我们使用 `alert` 函数来显示一个消息框,但您可以根据需要替换它。 希望这个例子对您有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值