`
zhangdaiping
  • 浏览: 129911 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

改变Ext.gird.GridPanel#Header样式的小例子

阅读更多
有网友问我怎么修改GridPanel#header的样式, 所以我就做了个例子



源码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Ext.GridPanel Example</title>

    <!-- ** CSS ** -->
    <!-- base library -->
    <link rel="stylesheet" type="text/css" href="../extjs/3.2.0/resources/css/ext-all.css" />

    <!-- ** Javascript ** -->
    <!-- ExtJS library: base/adapter -->
    <script type="text/javascript" src="../extjs/3.2.0/adapter/ext/ext-base.js"></script>

    <!-- ExtJS library: all widgets -->
    <script type="text/javascript" src="../extjs/3.2.0/ext-all-debug.js"></script>

    <!-- overrides to base library -->
    
    <!-- page specific -->
    <script type="text/javascript" src="gridpanel.js"></script>
    
	<style type="text/css">
		.x-grid-hcell-bgcolor {
			background-image: url() !important;
			background-color: red;
		}
		.x-grid-cell-bgcolor {
			background-color: gray;
		}
	</style>
</head>
<body>

    <h1>CExt.GridPanel Example</h1>
    
    <div id="example-ct" style="margin: 50px 50px;"></div>
    
</body>
</html>


Ext.onReady(function() {
    var bd = Ext.getBody();
    
    var store = new Ext.data.ArrayStore({
        fields: [{
            name: 'value'
        }, {
            name: 'text'
        }]
    });
    
    var data = [['1', 'One'], ['2', 'Two'], ['3', 'Three'], ['4', 'Four'], ['5', 'Five'], ['6', 'Six'], ['7', 'Seven'], ['8', 'Eight'], ['9', 'Nine'], ['10', 'Ten'], ['11', 'Eleven'], ['12', 'Twelve'], ['13', 'Thirteen'], ['14', 'Fourteen'], ['15', 'Fifteen'], ['16', 'Sixteen']];
    
    store.loadData(data);
    
    var enableHdMenu = false;
    var panel = new Ext.grid.GridPanel({
        renderTo: 'example-ct',
        width: 500,
        height: 300,
        store: store,
        columns: [{
            header: 'ID',
            dataIndex: 'value'
        }, {
            header: 'Name',
            dataIndex: 'text'
        }],
        enableHdMenu: enableHdMenu,
        viewConfig: {
            templates: {
				hcell : new Ext.Template(
	                '<td class="x-grid3-hd x-grid3-cell x-grid-hcell-bgcolor x-grid3-td-{id} {css}" style="{style}"><div {tooltip} {attr} class="x-grid3-hd-inner x-grid3-hd-{id}" unselectable="on" style="{istyle}">', enableHdMenu ? '<a class="x-grid3-hd-btn" href="#"></a>' : '',
	                '{value}<img class="x-grid3-sort-icon" src="', Ext.BLANK_IMAGE_URL, '" />',
	                '</div></td>'),
				cell: new Ext.XTemplate(
	                '<td class="x-grid3-col x-grid3-cell {cellbgcolor:this.cellBackgroudColor} x-grid3-td-{id} {css}" style="{style}" tabIndex="0" {cellAttr}>',
	                '<div class="x-grid3-cell-inner x-grid3-col-{id}" unselectable="on" {attr}>{value}</div>',
	                '</td>', {
						cellBackgroudColor: function() {
                            var o = arguments[1];
							if (o.css.indexOf('x-grid3-cell-first') != -1) {
								return 'x-grid-cell-bgcolor';
							}
							return '';
						}
					})
			}
        }
    });
})
分享到:
评论
3 楼 zhangdaiping 2010-07-07  
今天在review GridView源码的时候, 发现getRowClass函数, 用来自定义列表行样式

之前因为看的是API, 这个函数直接让我给忽略了.

官方是这样注释的
    /**
     * Override this function to apply custom CSS classes to rows during rendering.  You can also supply custom
     * parameters to the row template for the current row to customize how it is rendered using the <b>rowParams</b>
     * parameter.  This function should return the CSS class name (or empty string '' for none) that will be added
     * to the row's wrapping div.  To apply multiple class names, simply return them space-delimited within the string
     * (e.g., 'my-class another-class'). Example usage:
    <pre><code>
viewConfig: {
    forceFit: true,
    showPreview: true, // custom property
    enableRowBody: true, // required to create a second, full-width row to show expanded Record data
    getRowClass: function(record, rowIndex, rp, ds){ // rp = rowParams
        if(this.showPreview){
            rp.body = '&lt;p>'+record.data.excerpt+'&lt;/p>';
            return 'x-grid3-row-expanded';
        }
        return 'x-grid3-row-collapsed';
    }
},
    </code></pre>
     * @param {Record} record The {@link Ext.data.Record} corresponding to the current row.
     * @param {Number} index The row index.
     * @param {Object} rowParams A config object that is passed to the row template during rendering that allows
     * customization of various aspects of a grid row.
     * <p>If {@link #enableRowBody} is configured <b><tt></tt>true</b>, then the following properties may be set
     * by this function, and will be used to render a full-width expansion row below each grid row:</p>
     * <ul>
     * <li><code>body</code> : String <div class="sub-desc">An HTML fragment to be used as the expansion row's body content (defaults to '').</div></li>
     * <li><code>bodyStyle</code> : String <div class="sub-desc">A CSS style specification that will be applied to the expansion row's &lt;tr> element. (defaults to '').</div></li>
     * </ul>
     * The following property will be passed in, and may be appended to:
     * <ul>
     * <li><code>tstyle</code> : String <div class="sub-desc">A CSS style specification that willl be applied to the &lt;table> element which encapsulates
     * both the standard grid row, and any expansion row.</div></li>
     * </ul>
     * @param {Store} store The {@link Ext.data.Store} this grid is bound to
     * @method getRowClass
     * @return {String} a CSS class name to add to the row.
     */
2 楼 zhangdaiping 2010-07-07  
joehe 写道
好好的一个东西被你修改成这样了,真是悲剧

呃, 只是做个例子, 教人怎么改Tpl....
1 楼 joehe 2010-07-06  
好好的一个东西被你修改成这样了,真是悲剧

相关推荐

    Ext grid合并单元格

    根据提供的文件信息,我们可以深入探讨如何在 Ext JS 中实现 Grid 的单元格合并功能。此案例主要涉及到了自定义 GridView 的 `renderHeaders` 方法来达到单元格合并的目的,并且还涉及了模板(Template)的使用、...

    Extjs2.0动态加载gird的例子

    var grid = new Ext.grid.GridPanel({ store: store, cm: cm, viewConfig: { forceFit: true // 自适应列宽 }, bbar: new Ext.PagingToolbar({ store: store, displayInfo: true, pageSize: 25 }) }); ```...

    Ext2.0 javascript类库.rar

    主要包括data,widget,form,gird,dd,menu,其中最强大的应该算gird了,编程思想是基于面对对象编程(oop),扩展性相当的好.可以自己写扩展.自己定义命名空间.web应用可能感觉太大.不过您可以根据需要按需加载您想要的类库...

    ext Gird 有滚动条功能

    在Ext Grid中,滚动条功能是至关重要的,特别是在处理大量数据时,它允许用户在不改变窗口大小的情况下浏览数据。本篇文章将深入探讨Ext Grid的滚动条功能,以及如何实现和自定义这一特性。 首先,我们要理解Ext ...

    EXT JSON Grid示例

    本例采用PHP,json, sqlite,来显示一个EXT3.0的Grid,需要PHP环境,可以用xampp集成包。 部署后访问http://localhost/ExtSample/employee.php

    ext超酷的grid中放图片(ext3.2.1)

    var grid = new Ext.grid.GridPanel({ store: myStore, // 数据源 columns: [ { header: "图片", width: 100, dataIndex: 'imageUrl', xtype: 'imagecolumn' } // 自定义列 ] }); ``` 这里,我们创建了一个...

    Ext JS权威指南

    第10章和第11章分别详细介绍了重构后的gird和与gird同源的树;第12~16章分别讲解了表单、窗口、按钮、菜单、工具条、图形、图表,以及其他组件和实用功能;第17~19章分别介绍了ext.direct、动画功能和拖放功能;第20...

    ext grid 导出excel 代码实例

    - 处理样式和格式:EXT Grid的样式无法直接应用于Excel,所以你可能需要在构建Excel文件时指定单元格的样式。 - 处理大数据量:如果数据量过大,可能需要分批导出或者使用服务器端处理。 - 支持国际化:考虑不同语言...

    ExtGridDemo

    11. **主题(Theme)**:ExtJS提供多种视觉样式,你可以根据项目需求选择合适的主题,或者自定义CSS样式。 以上是"ExtGridDemo"可能涵盖的主要知识点。这个示例将帮助初学者理解如何在实际项目中运用ExtJS 5.1的...

    jq-extgrid v1.2 表格插件

    extgrid 是一款jquery上的gird插件 界面风格采用了类似easyui extjs 界面风格样式 可通过css修改自己想要的样式 extgrid具有列大小 位置改变 排序 分组 分页 工具栏 扩展行 rowNumber 多选列 编辑列 行列锁 ajax...

    Ext扩展控件-------可以通过下拉列表框选择每页的分页条数

    在EXT(Ext JS)框架中,分页是数据网格(Grid)中常用的功能,用于处理大量数据时提高性能和用户体验。EXT Grid控件允许用户滚动查看数据,而不是一次性加载所有记录,这使得页面加载更快,资源消耗更低。然而,...

    表格Ext js源代码

    在本资源中,我们关注的是"表格Ext js gird源代码",这涉及到Ext JS中的Grid Panel组件,它是展示和操作数据集的主要工具。 Grid Panel是Ext JS中的核心组件之一,用于显示结构化的数据,通常以表格的形式。它支持...

    Gird组件 Part-3:范例RSSFeed Viewer

    在YAHOO.ext.gird包中,大多数类是设计成为“即插即用plug and play”的,可扩展的extended和可自定义的customized,能以最小量的代码插入轻松到web程序中。 要测试和创建一个实现gird的范例,我决定做一个简单的,...

    Ext grid中渲染进度条,超帅 源码-----下载不扣分,回帖加1分,欢迎下载,童叟无欺。

    Ext grid中渲染进度条,超帅 源码-----下载不扣分,回帖加1分,欢迎下载,童叟无欺。Ext grid中渲染进度条,超帅 源码-----下载不扣分,回帖加1分,欢迎下载,童叟无欺。Ext grid中渲染进度条,超帅 源码-----下载不扣分...

    Ext扩展控件-----可以在代码中动态为表格增加一列或者删除一列

    在EXT JS这个强大的JavaScript框架中,开发者经常需要处理各种数据展示和操作,而表格(Grid)是其中常用的一种组件。EXT Grid控件提供了一个灵活且功能丰富的界面来展示和操作数据,而“Ext扩展控件”则进一步增强...

    Gird.zip mfc 写的GIRD 源码

    4. CGridCtrl类:熟悉GIRD控件的API,如添加列、插入行、设置单元格样式和事件处理。 5. MFC事件处理机制:了解ON_MESSAGE、ON_COMMAND、ON_BN_CLICKED等宏的用法,以及如何编写消息映射函数。 通过深入研究这两个...

    ext js 2.2

    主要包括data,widget,form,gird,dd,menu,其中最强大的应该算gird了,编程思想是基于面对对象编程(oop),扩展性相当的好.可以自己写扩展.自己定义命名空间.web应用可能感觉太大.不过您可以根据需要按需加载您想要的类库...

    ext-3.0-rc3

    主要包括data,widget,form,gird,dd,menu,其中最强大的应该算gird了,编程思想是基于面对对象编程(oop),扩展性相当的好.可以自己写扩展.自己定义命名空间.web应用可能感觉太大.不过您可以根据需要按需加载您想要的类库...

    ext js2.0 json java web 项目例子

    一个简单的ext java web项目 有gird form tree boder布局 如果有人觉的有用,会继续完善

    VC-MS-GIRD.rar_CellDemo _MS GIRD_gird_表格 excel vc_表格 vc

    【标题】"VC-MS-GIRD.rar" 是一个基于Visual C++(简称VC)开发的电子表格应用程序,它模仿了MS OFFICE中的表格处理软件,如Microsoft Excel的风格。这个项目名为"CellDemo _MS GIRD_gird_表格 excel vc_表格 vc",...

Global site tag (gtag.js) - Google Analytics