Ext.grid.EditorGridPanel的使用、修改記錄的獲取及提交方法
- <HTML>??
- ?<HEAD>??
- ??<TITLE>可編輯表格面板EditorGridPanel</TITLE>??
- ??<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8">??
- ??<link?rel="stylesheet"?type="text/css"?href="extjs2.0/resources/css/ext-all.css"?mce_href="extjs2.0/resources/css/ext-all.css"?/>??
- ??<mce:script?type="text/javascript"?src="extjs2.0/adapter/ext/ext-base.js"?mce_src="extjs2.0/adapter/ext/ext-base.js"></mce:script>??
- ??<mce:script?type="text/javascript"?src="extjs2.0/ext-all.js"?mce_src="extjs2.0/ext-all.js"></mce:script>??
- ??<mce:script?type="text/javascript"?src="extjs2.0/source/locale/ext-lang-zh_CN.js"?mce_src="extjs2.0/source/locale/ext-lang-zh_CN.js"></mce:script>??
- ??<mce:script?type="text/javascript"><!--??
- ?Ext.onReady(function(){??
- ??Ext.BLANK_IMAGE_URL?=?'../../extjs2.0/resources/images/default/s.gif';??
- ??Ext.QuickTips.init();??
- ??Ext.form.Field.prototype.msgTarget?=?'qtip';??
- ??//創建表格數據??
- ??var?data?=?[??
- ???[1,'張三','男',new?Date(1979,09,13),29,'zhang@abc.com'],??
- ???[2,'李四','女',new?Date(1978,10,01),30,'li@abc.com'],??
- ???[3,'王五','男',new?Date(1981,01,01),27,'wang@abc.com']??
- ??];??
- ??//創建記錄類型Person,mapping值為字段值對應數組中數據的索引位置??
- ??var?Person?=?Ext.data.Record.create([??
- ???{name:?'personId',mapping:?0},??
- ???{name:?'personName',mapping:?1},??
- ???{name:?'personSex',mapping:?2},??
- ???{name:?'personBirthday',mapping:?3},??
- ???{name:?'personAge',mapping:?4},??
- ???{name:?'personEmail',mapping:?5}??
- ??]);??
- ??var?dataStore=new?Ext.data.Store({//配置數據集??
- ????reader:?new?Ext.data.ArrayReader({id:0},Person),??
- ????data:?data??
- ???});??
- ??//創建Grid表格組件??
- ??var?grid?=?new?Ext.grid.EditorGridPanel({??
- ???title?:?'Ext.grid.EditorGridPanel',??
- ???applyTo?:?'grid-div',??
- ???width:430,??
- ???height:280,??
- ???frame:true,??
- ???clicksToEdit:2,??
- ???store:?dataStore,??
- ???//方式一:對所有修改結果集中式提交??
- ???tbar:[{??
- ????text:'提交修改',??
- ????handler:function(){??
- ?????var?mr=dataStore.getModifiedRecords();//獲取所有更新過的記錄??
- ?????var?recordCount=dataStore.getCount();//獲取數據集中記錄的數量??
- ?????if(mr.length==0){??//?確認修改記錄數量??
- ???????alert("沒有修改數據!");??
- ???????return?false;??
- ?????}??
- ???????
- ?????var?recordModStr="[";//這里以josn方式保存??
- ?????for(var?i=0;i<mr.length;i++){??
- ??????alert("orginValue:"mr[i].modified["personEmail"]+",value:"+mr[i].data["personSex"]);//此處cell是否發生??
- ?????????????????????????????????????????????//更改可用mr[i].dirty來判斷??
- ??????recordModStr+="{personName:"+mr[i].data["personName"]+",personSex:"+mr[i].data["personSex"]+",personBirthday:"??
- ???????????+mr[i].data["personBirthday"]+",personAge:"+mr[i].data["personAge"]+",personEmail:"+mr[i].data["personEmail"]+"}";??
- ???????if(i<mr.length-1)??
- ????????????????recordModStr+=",";??
- ?????}??
- ?????recordModStr+="]";??
- ?????alert(recordModStr);??
- ?????//向后臺提交請求?Ext.Ajax.request(requestCofig);//將recordModStr傳入??
- ???}??
- ???}],??
- ???columns:?[//配置表格列??
- ????{header:?"id",?width:?40,?dataIndex:?'personId'},??
- ????{header:?"姓名",?width:?70,?dataIndex:?'personName',??
- ?????editor:new?Ext.form.TextField({??
- ??????allowBlank?:?false??
- ?????})??
- ????},??
- ????{header:?"性別",?width:?40,?dataIndex:?'personSex',??
- ?????editor:new?Ext.form.ComboBox({??
- ??????editable?:?false,??
- ??????displayField:'sex',??
- ??????mode:?'local',??
- ??????triggerAction:?'all',??
- ??????store:new?Ext.data.SimpleStore({??
- ???????fields:?['sex'],??
- ???????data?:?[['男'],['女']]??
- ??????})??
- ?????})??
- ????},??
- ????{header:?"生日",?width:?100,?dataIndex:?'personBirthday',??
- ?????editor:new?Ext.form.DateField(),??
- ?????renderer:Ext.util.Format.dateRenderer('Y年m月d日')??
- ????},??
- ????{header:?"年齡",?width:?40,?dataIndex:?'personAge',??
- ?????editor:new?Ext.form.NumberField(),renderer:isEdit??
- ????},??
- ????{header:?"電子郵件",?width:?120,?dataIndex:?'personEmail',??
- ?????editor:new?Ext.form.TextField({??
- ??????vtype:'email'??
- ?????})??
- ????}??
- ???]??
- ??})??
- ??//方式二:對修改結果實時提交,這里對年齡實時提交??
- ??function?isEdit(value,record){??
- ????//向后臺提交請求??
- ???return?value;??
- ??}??
- function ?afterEdit(obj){???? //每次更改后,觸發一次該事件 ??
- ??????????alert("orginalValue:"+obj.originalValue+",value:"+obj.value);??
- ??????}??
- ?????grid.on("afteredit",?afterEdit,?grid);??
- ?});??
- ????
- //?--></mce:script> ??
- ?</HEAD>??
- ?<BODY?style="margin=10?10?10?10;"?mce_style="margin=10?10?10?10;">??
- ?<div?id='grid-div'></div>??
- ?</BODY>??
- </HTML>??
轉自: http://blog.csdn.net/gaoyusi4964238/archive/2009/07/25/4378498.aspx
posted on 2010-09-09 17:31 duansky 閱讀(2822) 評論(1) 編輯 收藏 所屬分類: Ext