ExtJS下grid的一些属性说明


Posted in Javascript onDecember 13, 2009

1.界面修改(css style):
Extjs中界面风格与我们产品本身的风格有很大不同,从边框、选中行的颜色到鼠标移动到的行的颜色、菜单等,几乎都不同。Extjs对这些样式的设置都是由css完成的。如:
选中行的颜色就可用如下设置完成:
.x-grid3-row-selected{background:#c6e2ff!important;}
其他的都类似,只要找到对应的class, 然后设置要修改的部分即可。

2. 属性的作用(About Ext.grid. GroupingView, EditorGridPanel):
Extjs的grid功能强大,如排序、隐藏列或移动列等,这些都有一些属性与其对应,可以选择要还是不要。其中一些的属性和其作用如下:
*. EditorGridPanel:
border: false, //grid的边界
autoHeight: true, //grid的高度是否要用指定的高度
enableColumnMove: false, //grid的列是否可以移动
enableHdMenu: false, //在列的header是否要有下拉菜单
trackMouseOver: true, //当鼠标移过行时,行是否要highlight
stripeRows: true, //让grid相邻两行背景色不同
*. GroupingView:
在要显示的数据中,根据它们的某个数据点进行分组,分组显示。这个数据点由*.GroupingStore中的groupField决定。*.GroupingView设置这个分组显示的grid的一些关于组的显示属性。如:
forceFit:true, //是否根据grid的宽度调整列的宽度,防止水平scrollbar的出现
enableGroupingMenu: false, //控制header的下拉菜单中是否有group的选项(Group By This Field, Show in Groups(checkbox))
showGroupName: true,
//用来分组的数据点这一列的header是否要随group name一起显示
hideGroupedColumn: true, //用来分组的数据点这一列是否要显示
startCollapsed: false, //一开始进到grid这页,它的group是合起还是展开
scrollOffset: -1, //为垂直的scrollbar留下的space(默认是19px)

3.在单元格中添加图片:
在Ext.grid.ColumnModel中对应于加图片的列,用它的render链接到一个函数进行添加。如:
var colModel = new Ext.grid.ColumnModel([
{header:”com”, render: AddImgs.createDelegate(this)},
{header:”test”, width:200, sortable:false}
]);
响应函数如下:
AddImgs = function(value,p,record){
if(record.data.descrip != "")
{
p.attr='ext:qtip="Add to playlist" style="background-image:url(/imgs/icn_view.gif) !important; background-position: center 2px; background-repeat: no-repeat;cursor: pointer;"';
}
}
函数中的record.data是grid的数据,而着色的就是要添加的图片的路径和图片名。

4.当显示内容的字数超过单元格可以显示的字数时,如何让其自动换行(how to wrap text when the length of characters is more than the width of the column):
设置这些单元格的所用类的css即可。 如:
.x-grid3-cell-inner{
white-space:normal;
overflow:visible;
}
需要注意的是:overflow的默认值是hidden. 当加上white-space之后,本来wrap就可以了,但是单元格的高度还是一行的高度,所以数据除了第一行,其它都看不到。只有把overflow的值改为visible后,单元格所在行的高度才会随着数据的行数而调整。

5.当一开始进入页面时,让所有的group除了第一个group展开(collapsed)外,其它的group都合上(folded):
首先通过设置属性startCollapsed让所有group都合上: startCollapsed:true;
然后在store.load({callback: function(records,o,s) {ToggleFirstGroup();} })中调用函数把第一个group展开:
//gridView是该grid所用的view, 如(var gv = new Ext.grid.GroupingView({});).

function ToggleFirstGroup(gridView) 
{ 
var grNum = gridView.getGroups().length; 
for (var i = 0; i < grNum ; i++) 
{ 
var firstGroupID = gridView.getGroups()[i].id; 
if(firstGroupID && firstGroupID != "") 
{ 
gridView.toggleGroup(firstGroupID); 
break; 
} 
} 
}

6.date format: 数据为9/24/2008
1).这种format的结果是:Web Sep 24 00:00:00 UTC+0800 2008
{
header: dHeader,
width: 90,
sortable: true,
dateFormat: 'Y-m-d', //dateFormat是'm/d/Y'的话,得到的结果一样
dataIndex: 'date'
},
2). 这种format的结果是: 2008-09-24
{
header: dHeader,
width: 90,
sortable: true,
renderer: Ext.util.Format.dateRenderer('Y-m-d'), //format是'm/d/Y',结果是”09/24/2008”
dataIndex: 'date'
},
找到的一些关于Class Date的format及其输出的描述(http://extjs.com/deploy/ext/docs/output/Date.html):
****************************
Format Output Description
------ ---------- --------------------------------------------------------------
d 10 Day of the month, 2 digits with leading zeros
D Wed A textual representation of a day, three letters
j 10 Day of the month without leading zeros
l Wednesday A full textual representation of the day of the week
S th English ordinal day of month suffix, 2 chars (use with j)
w 3 Numeric representation of the day of the week
z 9 The julian date, or day of the year (0-365)
W 01 ISO-8601 2-digit week number of year, weeks starting on Monday (00-52)
F January A full textual representation of the month
m 01 Numeric representation of a month, with leading zeros
M Jan Month name abbreviation, three letters
n 1 Numeric representation of a month, without leading zeros
t 31 Number of days in the given month
L 0 Whether it's a leap year (1 if it is a leap year, else 0)
Y 2007 A full numeric representation of a year, 4 digits
y 07 A two digit representation of a year
a pm Lowercase Ante meridiem and Post meridiem
A PM Uppercase Ante meridiem and Post meridiem
g 3 12-hour format of an hour without leading zeros
G 15 24-hour format of an hour without leading zeros
h 03 12-hour format of an hour with leading zeros
H 15 24-hour format of an hour with leading zeros
i 05 Minutes with leading zeros
s 01 Seconds, with leading zeros
O -0600 Difference to Greenwich time (GMT) in hours
T CST Timezone setting of the machine running the code
Z -21600 Timezone offset in seconds (negative if west of UTC, positive if east)
**********************************
下面是一些format的格式及其对应结果:数据同上,用renderer: Ext.util.Format.dateRenderer(format)
“Y-m-d” --> 2008-09-24
“y-m-d” --> 08-09-24
“F j, Y” --> September 24, 2008
“F j, y” --> September 24, 08
“F j, Y, g:i A” --> September 24, 2008, 12:00 AM
Javascript 相关文章推荐
更换select下拉菜单背景样式的实现代码
Dec 20 Javascript
Jquery UI震动效果实现原理及步骤
Feb 04 Javascript
js相册效果代码(点击创建即可)
Apr 16 Javascript
js不能获取隐藏的div的宽度只能先显示后获取
Sep 04 Javascript
JavaScript基于ajax编辑信息用法实例
Jul 15 Javascript
Bootstrap每天必学之进度条
Nov 30 Javascript
js滚动条平滑移动示例代码
Mar 29 Javascript
jQuery插件passwordStrength密码强度指标详解
Jun 24 Javascript
JavaScript中绑定事件的三种方式及去除绑定
Nov 05 Javascript
快速解决brew安装特定版本flow的问题
May 17 Javascript
小程序ios音频播放没声音问题的解决
Jul 11 Javascript
node创建Vue项目步骤详解
Mar 06 Javascript
用jquery ajax获取网站Alexa排名的代码
Dec 12 #Javascript
jValidate 基于jQuery的表单验证插件
Dec 12 #Javascript
ASP小贴士/ASP Tips javascript tips可以当桌面
Dec 10 #Javascript
Ext.MessageBox工具类简介
Dec 10 #Javascript
模仿JQuery.extend函数扩展自己对象的js代码
Dec 09 #Javascript
js 与或运算符 || &amp;&amp; 妙用
Dec 09 #Javascript
测试你的JS的掌握程度的代码
Dec 09 #Javascript
You might like
QQ登录 PHP OAuth示例代码
2011/07/20 PHP
PHP+Memcache实现wordpress访问总数统计(非插件)
2014/07/04 PHP
php实现的Captcha验证码类实例
2014/09/22 PHP
php遍历类中包含的所有元素的方法
2015/05/12 PHP
php将html转成wml的WAP标记语言实例
2015/07/08 PHP
给大家分享几个常用的PHP函数
2017/01/15 PHP
Laravel 微信小程序后端实现用户登录的示例代码
2019/11/26 PHP
PHP如何使用JWT做Api接口身份认证的实现
2020/02/03 PHP
ExtJS PropertyGrid中使用Combobox选择值问题
2010/06/13 Javascript
javascript中的变量作用域以及变量提升详细介绍
2013/10/24 Javascript
JS简单限制textarea内输入字符数量的方法
2015/10/14 Javascript
artDialog+plupload实现多文件上传
2016/07/19 Javascript
ES6概念 Symbol.keyFor()方法
2016/12/25 Javascript
js设置文字颜色的方法示例
2016/12/30 Javascript
微信小程序手势操作之单触摸点与多触摸点
2017/03/10 Javascript
ionic 3.0+ 项目搭建运行环境的教程
2017/08/09 Javascript
JavaScript数组push方法使用注意事项
2017/10/30 Javascript
详解小程序rich-text对富文本支持方案
2018/11/28 Javascript
使用react render props实现倒计时的示例代码
2018/12/06 Javascript
Vue组件的使用及个人理解与介绍
2019/02/09 Javascript
JavaScript 面向对象基础简单示例
2019/10/02 Javascript
JsonProperty 的使用方法详解
2019/10/11 Javascript
使用Python的Tornado框架实现一个Web端图书展示页面
2016/07/11 Python
python实现rsa加密实例详解
2017/07/19 Python
Python基于回溯法子集树模板解决旅行商问题(TSP)实例
2017/09/05 Python
对Python中range()函数和list的比较
2018/04/19 Python
用Python获取摄像头并实时控制人脸的实现示例
2019/07/11 Python
对Python 中矩阵或者数组相减的法则详解
2019/08/26 Python
CSS3属性选择符介绍
2008/10/17 HTML / CSS
如何用border-image实现文字气泡边框的示例代码
2020/01/21 HTML / CSS
JDK安装目录下有哪些内容
2014/08/25 面试题
Linux管理员面试经常问道的相关命令
2013/04/29 面试题
常用UNIX 命令(Linux的常用命令)
2015/12/26 面试题
违纪检讨书2000字
2014/02/08 职场文书
超市国庆节促销方案
2014/02/20 职场文书
SQL Server中常用截取字符串函数介绍
2022/03/16 SQL Server