---
title: "extjs cellediting"
author: "Darlyn"
date: "2014-04-25T14:39:58Z"
tags: []
categories: ["Web前端"]
slug: "extjs-cellediting"
draft: false
lastmod: "2014-04-25T16:38:22Z"
id: 2054561
url: "https://darlyn.iteye.com/blog/2054561"
---

1.项目使用extjs cellediting，使用后grid中的数据就是无法被修改，调了一上午加下午半小时终于知道问题所在：store中的api一定要有update项，且update指到的文件不能是数据原有文件。
store：

```java

Ext.define('×××.store.×××',{
    extend:'Ext.data.Store',
    model:'×××.model.×××',
    autoLoad: true,
    autoSync: true,
    storeId: '×××',
    proxy:{
    	type:'ajax',
    	url:'data/×××.json',
    	api:{
    		read:'data/×××.json',
    		update:'data/×××Update.json',

    	},
    	reader:{
    		type:'json',
    		root:'×××',
    		successProperty:'success',
    		messageProperty:'message'
    	}
｝

```

grid:

```java

this.editing = Ext.create('Ext.grid.plugin.CellEditing', {
    		ptype:'cellediting',
        	clicksToEdit: 1,
        	autoCancel:false,
        	listeners:{
        		validateedit:{        			fn:this.000000000,
        			scope:this
        		}
        	}
    	});
Ext.apply(this,{
plugins:[this.editing],
……
});

000000000: function(editor, e, options) {
    	console.debug(" cell edit listener ");
        console.log(editor);
        console.log(e);
        console.log("e.value:"+e.value);
        console.log("options:"+options);
    }

```


2.extjs中和 Date相关的小问题
如果想要只允许用户选择今天之后的日期，只需设置：

```java
minValue: new Date(),
```

设置在grid中显示的日期格式：

```java
renderer: Ext.util.Format.dateRenderer('Y-m-d'),
```

示例代码如下：

```js

{
    header: 'Deadline',
    dataIndex: 'deadline',
    flex:1,
    minWidth:100,
    renderer: Ext.util.Format.dateRenderer('Y-m-d'),
    field: {
         xtype: 'datefield',
         allowBlank: false,
         format: 'Y-m-d', //选择日期时显示的日期格式
         renderer: this.formatDate,
         minValue: new Date(),
         value:this.formatDate(value)
    }

```