---
title: "Extjs 4 解决 grid + checkboxmodel+rowediting 对齐的bug "
author: "快乐的牛"
date: "2012-02-11T14:09:07Z"
tags: []
categories: ["Web前端"]
slug: "extjs-4-grid-checkboxmodel-rowediting-bug"
draft: false
lastmod: "2012-02-11T14:15:40Z"
id: 1402833
url: "https://kldn.iteye.com/blog/1402833"
---

在Extjs 4.0中，实现 行选择、行编辑很简单，但是checkboxmodel 和 rowediting插件组合存在一个对齐的bug。

在线demo:[http://extjshelp.sinaapp.com/rowedit/](http://extjshelp.sinaapp.com/rowedit/)

 

grid + checkboxmodel 的显示效果如下：

![](http://dl.iteye.com/upload/attachment/0063/0300/a8a4c77d-648d-3ec3-8c14-3862b526e5ae.png)  
 双击编辑一行：

![](http://dl.iteye.com/upload/attachment/0063/0304/0fbeeb59-a8e6-33cc-83bd-ee7592a5f662.png)  
 注意到，编辑器没有和grid表头对齐。原因就是我们加了一列checkbox。这是Extjs 4.0 的bug，rowediting 插件和checkboxmodel组件之间没有配合好。

解决方法，让item项的编辑器往右边"挤一挤":

 

```
{text:'Item',dataIndex:'item',editor:{ margin:'0 0 0 22 ' }},
```

现在看起来整齐了：

![](http://dl.iteye.com/upload/attachment/0063/0307/baf61dfc-98dc-3a75-b7f1-9f26ec9e6a54.png)

 完整的代码：

 

```
Ext.onReady(function(){
	var store = {
		type:'array',
		fields:["item","price"],
		data:[
			["Steve Bible",0.99],
			["Steve Bible",0.99],
			["Steve Bible",0.99],
			["Steve Bible",0.99]
		]
	}
	var checkmodel = Ext.create('Ext.selection.CheckboxModel')
	var rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
		clicksToMoveEditor: 2,
		autoCancel: false
        })
	
	var grid = Ext.create("Ext.grid.Panel",{
		store:store,
		plugins: [rowEditing],
		selModel:checkmodel,
		columns:[
			{text:'Item',dataIndex:'item',editor:{ margin:'0 0 0 22 ' }},
			{text:'Price',dataIndex:'price',editor:{type:'numberfield'}},
		],
		region:'center'
	})
	Ext.create('Ext.container.Viewport',{
		layout:'border',
		items:[
			grid
		]
	})
})
```

 

 

```
<html>
	<head>
	<link rel="stylesheet" type="text/css" href="../extjs/resources/css/ext-all.css">
	<script type="text/javascript" src="../extjs/ext-all.js"></script>
	<script type="text/javascript" src="app.js"></script>
	</head>
	<body>
	</body>
</html>
```