`
gtgt1988
  • 浏览: 114253 次
  • 性别: Icon_minigender_1
  • 来自: 合肥
社区版块
存档分类
最新评论

extjs-EditorGridPanel学习

 
阅读更多

重要的方法:grid.getStore().getModifiedRecords();获得编辑后的结果

 text: "增加",  

                handler: function() {  

                    var Plant = store.recordType;  

                    var p = new Plant({  

                        common: 'New Plant 1',  

                        light: 'Mostly Shade',  

                        price: 0,  

                        availDate: (new Date()).clearTime(),  

                        indoor: false  

                    });  

                    grid.stopEditing();  

                    store.insert(0, p);  //插入第一行

                    grid.startEditing(0, 0);  

Ext.BLANK_IMAGE_URL = '../../resources/images/default/s.gif';  
Ext.QuickTips.init();  
Ext.onReady(function() {  
    //Ext.Msg.alert("sf0", "sdf");  
    //格式化日期  
    function formatDate(value) {  
        return value ? value.dateFormat('Y年m月d日') : '';  
    }  
  
    // 别名  
    var fm = Ext.form;  
  
    //checkbox选择模型  
    var sm = new Ext.grid.CheckboxSelectionModel({ checkOnly: true });  
  
    //构造一个只能包含checkbox的列  
    var checkColumn = new Ext.grid.CheckColumn({  
        header: 'Indoor?', 
        dataIndex: 'indoor',  
        width: 55  
    });  
  
    // 构造ColumnModel  
    var cm = new Ext.grid.ColumnModel({  
        columns: [  
        sm,  
        {  
            id: 'common',  
            header: 'Common Name',  
            dataIndex: 'common',  
            width: 220,  
            // 使用上边定义好的别名  
            editor: new fm.TextField({  
                allowBlank: false  
            })  
        }, {  
            header: 'Light',  
            dataIndex: 'light',  
            width: 130,  
            editor: new fm.ComboBox({  
                typeAhead: true,  
                triggerAction: 'all',  
                transform: 'light',  
                lazyRender: true,  
                listClass: 'x-combo-list-small'  
            })  
        }, {  
            header: 'Price',  
            dataIndex: 'price',  
            width: 70,  
            align: 'right',  
            renderer: 'usMoney',  
            editor: new fm.NumberField({  
                allowBlank: false,  
                allowNegative: false,  
                maxValue: 100000  
            })  
        }, {  
            header: 'Available',  
            dataIndex: 'availDate',  
            width: 95,  
            renderer: formatDate,  
            editor: new fm.DateField({  
                format: 'Y年m月d日',  
                minValue: '01/01/06',  
                disabledDays: [0, 6],  
                disabledDaysText: 'Plants are not available on the weekends'  
            })  
        },
        checkColumn  
    ],  
        defaults: {  
            sortable: true  
        }  
    });  
  
  
    // 构造一个Store对象  
    var store = new Ext.data.Store({  
  
        url: 'plants.xml',  
  
        reader: new Ext.data.XmlReader(  
            {  
              record:'plant' 
            },  
  
            [  
                { name: 'common', type: 'string' },  
                { name: 'botanical', type: 'string' },  
                { name: 'light' },  
                { name: 'price', type: 'float' },  
                { name: 'availDate', mapping: 'availability', type: 'date', dateFormat: 'm/d/Y' },  
               { name: 'indoor', type: 'bool' }  
            ]  
        ),  
        sortInfo: { field: 'common', direction: 'ASC' }  
    });  
  
    // 构造可编辑的grid  
    var grid = new Ext.grid.EditorGridPanel({  
        //sm: new Ext.grid.RowSelectionModel({ singleSelect: false }),  
        sm: sm,  
        store: store,  
        cm: cm,  
        renderTo: 'grid',  
        width: 600,  
        height: 300,  
        autoExpandColumn: 'common',  
        title: 'Edit Plants?',  
        frame: true,  
        plugins: checkColumn,  
        clicksToEdit: 1,  //默认2次双击才触发编辑框事件
        listeners: {  
            "afterEdit": {  
                fn: afterEdit,  
                scope: this  
            }  
        }, 
    	bbar: new Ext.PagingToolbar({
			pageSize : 5,
			store : store,
			firstText : '第一页',
			nextText : '下一页',
			prevText : '上一页',
			refreshText : '刷新',
			lastText : '最后一页',
			beforePageText : '当前',
			afterPageText : '页/共{0}页',
			displayInfo : true,
			displayMsg : '显示第 {0} 条到 {1} 条记录,一共 {2} 条',
		
			emptyMsg : "没有记录"
			
		}),
        tbar: [{  
            text: "保存",  
            handler: function() { 
        	 var  mod=grid.getStore().getModifiedRecords();
        	 for ( var i = 0; i < mod.length; i++) {
     			alert(mod[i].data.common);
     		}
                var mod = store.modified;  
               // updateData(mod);  
            }  
        },  
            '-',  
            {  
                text: "增加",  
                handler: function() {  
                    var Plant = store.recordType;  
                    var p = new Plant({  
                        common: 'New Plant 1',  
                        light: 'Mostly Shade',  
                        price: 0,  
                        availDate: (new Date()).clearTime(),  
                        indoor: false  
                    });  
                    grid.stopEditing();  
                    store.insert(0, p);  
                    grid.startEditing(0, 0);  
                }  
            },  
            " ",  
            {  
                text: "删除",  
                handler: function() {  
                    var selModel = grid.getSelectionModel();  
                    if (selModel.hasSelection()) {  
                        Ext.Msg.confirm("警告", "确定要删除吗?", function(button) {  
                            if (button == "yes") {  
                                var selections = selModel.getSelections();  
                                Ext.each(selections, function(item) {  
                                    store.remove(item);  
                                   // store.removed.push(item);  
                                });  
                            }  
                           // alert(store.removed.length);  
                        });  
                    }  
                    else {  
                        Ext.Msg.alert("错误", "没有任何行被选中,无法进行删除操作!");  
                    }  
                }  
            }  
                ]  
    });  
  
    // 触发数据的加载  
    store.load();  
  
    //发送数据到服务器端进行更新  
//    function updateData(mod) {  
//        var json = [];  
//        Ext.each(mod, function(item) {  
//            json.push(item.data);  
//        });  
//        if (json.length >= 0) {  
//            Ext.Ajax.request({  
//                url: "EditGrid.aspx",  
//                params: { data: Ext.util.JSON.encode(json) },  
//                method: "POST",  
//                success: function(response) {  
//                    Ext.Msg.alert("信息", "数据更新成功!", function() { store.reload(); });  
//                },  
//                failure: function(response) {  
//                    Ext.Msg.alert("警告", "数据更新失败,请稍后再试!");  
//                }  
//            });  
//        }  
//        else {  
//            Ext.Msg.alert("警告", "没有任何需要更新的数据!");  
//        }  
//    }  
  
    //编辑后触发的事件,可在此进行数据有效性的验证  
    function afterEdit(e) {  
        if (e.field == 'common') {  
            if (e.value == '123') {  
                Ext.Msg.alert("错误", "大笨是人物不是植物", function() { grid.startEditing(e.row, e.column) });  
            }  
        }  
    }  
});  
分享到:
评论

相关推荐

    Extjs可编辑的EditorGridPanel

    NULL 博文链接:https://zxf-noimp.iteye.com/blog/629629

    Extjs EditorGridPanel中ComboBox列的显示问题

    在EXTJS中,EditorGridPanel是一种可编辑的表格组件,它允许用户直接在表格单元格内编辑数据。然而,当在EditorGridPanel中嵌入ComboBox(下拉选择框)作为编辑器时,可能会遇到一个问题,即ComboBox显示的不是其...

    extjs培训2011-12-17

    2. **docs**:API帮助文档,这对于理解和学习ExtJS提供的各种方法和属性至关重要。 3. **examples**:提供了许多实用的小示例,帮助开发者快速上手。 4. **resources**:存放了ExtJS UI资源文件,例如CSS样式和图片...

    extjs实例与学习资料

    因为前段时间有两个专案要用到extjs技术,所以自己学了一段时间,在专案才发现extjs的强大,无论对于开发者还是使用者他都是一场视觉盛宴,这里有我从学习开始做的一些笔记和例子也有自己收集的学习资料,里面包括...

    ExtJS in Action-英文原版-完整版

    2. 书籍《ExtJS in Action》:这本书是一本关于ExtJS的学习指南,适用于快速上手ExtJS框架的开发者。它被描述为比国内作者编写的同类型工具书质量更高,是英文原版的完整版。 3. 出版信息:该书由Manning ...

    ExtJS.in.Action

    通过这一章的学习,读者可以掌握ExtJS的核心概念,并为后续学习打下坚实的基础。 ### 事件处理机制 第三章“Events, Components, and Containers”深入讨论了ExtJS中的事件处理机制,组件和容器的概念及其使用方法...

    extjs 导入导出 Exel

    文件"Extjs利用服务器实现Excel数据导入editorgridpanel中显示_寒冰_新浪博客.mht"可能讲解了如何将Excel 文件的数据导入到EXTJS 的EditorGridPanel 中。导入过程一般包括: 1. 用户上传Excel 文件,EXTJS 通过...

    EXTJS讲解个人项目经历

    EXTJS 是一个强大的JavaScript前端框架,它主要用于构建富客户端应用,提供丰富的用户界面组件和灵活的可定制性。EXTJS 的核心在于其组件化的架构,允许开发者构建复杂的UI布局和功能丰富的应用程序。以下是对EXTJS...

    Extjs简名教程.pdf

    ### Extjs简名教程知识点概览 #### 一、ExtJS简介 - **定义与特点**:ExtJS是一款基于JavaScript...通过学习这些内容,开发者可以更好地掌握ExtJS的基本用法和高级特性,从而构建出功能强大且用户友好的Web应用程序。

    给Extjs的GridPanel增加“合计”行

    在EXTJS中,GridPanel是一种常用的组件,用于展示表格数据。在实际应用中,我们经常需要在GridPanel底部显示一行“合计”行,以便对某一列或多列的数据进行求和或其他统计操作。这篇博文“给Extjs的GridPanel增加...

    Extjs in action

    #### 学习Extjs的最佳资源 **Extjs in Action** 是一本专为希望深入了解Extjs框架的开发人员准备的书籍。它不仅涵盖了Extjs的基础知识,还深入探讨了如何构建可配置的复杂组件。本书由Jesus Garcia撰写,并由...

    extjs扩展标记

    1. **EXTJS组件**:EXTJS的核心是它的组件模型,包括GridPanel、TreePanel、PropertyGrid、EditorGridPanel、TabPanel、FormPanel、Panel、Window、ToolTip和FieldSet等。这些组件可以组合起来创建复杂的用户界面,...

    extjs xtype

    10. `editorgrid` - `Ext.grid.EditorGridPanel`:可编辑的表格,允许用户直接在表格中修改数据。 11. `grid` - `Ext.grid.GridPanel`:标准的表格组件,用于展示数据。 12. `paging` - `Ext.PagingToolbar`:分页...

    老师整理的extjs学习笔记

    ### ExtJS 学习笔记概览 #### 一、ExtJS 入门 **1.1 ExtJS 构成及如何引用** ExtJS 是一款基于 JavaScript 的开源框架,专为 Web 应用程序的前端界面设计。其核心优势在于提供了一套丰富的 UI 组件和强大的数据...

    Extjs 性能优化 High Performance ExtJs

    另外需要注意的是,当 `form` 与 `EditorGridPanel` 结合使用时,应当特别注意表单的状态管理,确保每次提交都是有意义的。 #### 四、字符串与对象之间的转换 在 Extjs 开发过程中,常常需要将字符串转换为对象或...

    EXTJS实用开发指南_个人整理笔记.pdf

    1. 基本控件:Box、Button、ColorPalette、Component、Container、CycleButton、DataView、DatePicker、Editor、EditorGridPanel、Grid、PagingToolbar、Panel、ProgressBar、SplitButton、TabPanel、TreePanel、...

    EXTJS 学习笔片段1

    EXTJS 学习笔片段1 Form ComboBox 远程ComboBox 替代页面上已经存在的Select控件 Grid EditorGridPanel 使用本地store Toolbar工具菜单创建 分页工具栏创建 Window 弹出处理window窗口(模态窗口) ...

    extjs的快速入门教程

    - **可编辑的表格(EditorGridPanel)**: - 在表格的基础上增加了编辑功能,用户可以直接修改数据。 #### 七、与服务器交互 - **数据存储(Store)**: - 存储和管理数据集,支持本地数据和远程数据加载。 - **...

    ExtJS下拉列表树控件

    对于ExtJS EditorGridPanel中ComboBox列的显示问题,可能是因为数据没有正确绑定或格式化问题,确保`store`已加载数据,并且在`renderer`函数中正确显示数据。 至于回显问题,即在编辑时显示已有的数据,需要确保在...

Global site tag (gtag.js) - Google Analytics