Extjs5 GridPanel RowEditing Notes 01

Ext.define(‘Ext.App.Areas.System.Para.ParaController‘, {

    extend: ‘Ext.app.ViewController‘,

    alias: ‘controller.ParaController‘,

    isEditing: false, // 编辑状态

    /* 刷新按钮点击 */
    onRefreshClick: function (button, e, eOpts) {
        var me = this;
        if (me.isEditing == false) {
            var grid = me.view.down(‘#paraGridPanel‘);
            Ext.apply(grid.store.proxy.extraParams, {});
            grid.store.load({ params: {} });
        }
    },

    /* 添加按钮点击 */
    onCreateClick: function (button, e, eOpts) {
        var me = this;
        if (me.isEditing == false) {
            var grid = me.view.down(‘#paraGridPanel‘);
            grid.store.insert(0, {});
            grid.editingPlugin.cancelEdit();
            grid.editingPlugin.startEdit(0, 0);
        }
    },

    /* 修改按钮点击 */
    onUpdateClick: function (button, e, eOpts) {
        var me = this;
        if (me.isEditing == false) {
            var grid = me.view.down(‘#paraGridPanel‘);
            var selections = grid.getSelection();
            grid.editingPlugin.cancelEdit();
            grid.editingPlugin.startEdit(selections[0], 0);
        }
    },

    /* 删除按钮点击 */
    onDeleteClick: function (button, e, eOpts) {
        var me = this;
        if (me.isEditing == false) {
            var grid = me.view.down(‘#paraGridPanel‘);
            var selections = grid.getSelection();
            if (selections.length > 0) {
                Ext.MessageBox.confirm(‘提示‘, ‘确定删除所选记录?‘, function (btn) {
                    if (btn == ‘yes‘) {
                        var ajaxUrl = grid.store.proxy.api.destroy;

                        var delArr = [];
                        for (var i = 0; i < selections.length; i++) {
                            delArr.push(selections[i].data[‘ID‘]);
                        }

                        Ext.Ajax.request({
                            url: ajaxUrl,
                            params: delArr.join(‘,‘),
                            success: function (response, opts) {
                                var json = Ext.decode(response.responseText);
                                if (json.status == true) {
                                    Ext.toast({
                                        html: ‘<span style="font-weight:bold;">‘ + json.info + ‘</span>‘,
                                        closable: false,
                                        align: ‘t‘,
                                        slideInDuration: 400,
                                        minWidth: 330
                                    });
                                    /* 移除删除项 */
                                    for (var i = 0; i < selections.length; i++) {
                                        grid.store.remove(selections[i]);
                                    }
                                } else {
                                    Ext.MessageBox.show({
                                        icon: Ext.MessageBox.ERROR,
                                        msg: json.info,
                                        buttons: Ext.MessageBox.OK
                                    });
                                }
                            },
                            failure: function (response, opts) {
                                Ext.MessageBox.show({
                                    msg: response.responseText,
                                    buttons: Ext.MessageBox.OK
                                });
                            }
                        });
                    }
                });
            }
        }
    },

    /* 添加或修改准备 */
    onBeforeEdit: function (editor, context, eOpts) {
        var me = this;

        if (me.isEditing != false)  // 进入了编辑状态则阻止
            context.cancel = true;
        me.isEditing = true;

        var updateButton = me.view.down(‘#update‘);
        if (updateButton.bind.disabled.lastValue == true && context.record.data[‘ID‘] != undefined) { // 判断编辑权限
            context.cancel = true;
            me.isEditing = false; // 修正编辑状态
        }

        /* 其他数据对应加载(如:省市联动) */
    },

    /* 添加或修改保存 */
    onEdit: function (editor, context, eOpts) {
        var me = this;
        var ajaxUrl = context.store.proxy.api.update;

        var originalValues = context.originalValues; // 原始数据
        var newValues = context.newValues; // 新数据

        if (newValues[‘ID‘] == undefined)
            ajaxUrl = context.store.proxy.api.create;

        /* Ext.Object.equals:字段值为null与字段值为‘‘也代表不相等,此处需要相反 */
        Ext.Object.each(originalValues, function (key, value, scope) {
            if (key != ‘‘ && value == null)
                originalValues[key] = ‘‘;
        });

        if (Ext.Object.equals(newValues, originalValues) == false) { /* 判断修改,避免不必要的提交 */
            Ext.Ajax.request({
                url: ajaxUrl,
                params: newValues,
                success: function (response, opts) {
                    var json = Ext.decode(response.responseText);
                    if (json.status == true) {
                        Ext.toast({
                            html: ‘<span style="font-weight:bold;">‘ + json.info + ‘</span>‘,
                            closable: false,
                            align: ‘t‘,
                            slideInDuration: 400,
                            minWidth: 330
                        });
                        /* 隐藏域赋值 */
                        if (context.record.data[‘ID‘] == undefined) {
                            context.record.set(‘ID‘, json.data[‘ID‘]);
                            context.record.set(‘CreateTime‘, json.data[‘CreateTime‘]);
                            /* 不是很理想的地方 */
                        }
                        context.store.commitChanges();
                    } else {
                        Ext.MessageBox.show({
                            icon: Ext.MessageBox.ERROR,
                            msg: json.info,
                            buttons: Ext.MessageBox.OK
                        });
                        context.store.rejectChanges();
                    }
                },
                failure: function (response, opts) {
                    Ext.MessageBox.show({
                        msg: response.responseText,
                        buttons: Ext.MessageBox.OK
                    });
                    context.store.rejectChanges();
                }
            });
        } else {
            context.store.commitChanges();
        }

        me.isEditing = false;
    },

    /* 添加或修改取消 */
    onCancelEdit: function (editor, context, eOpts) {
        var me = this;
        context.store.rejectChanges();
        me.isEditing = false;
    }
});
时间: 2024-10-29 18:08:48

Extjs5 GridPanel RowEditing Notes 01的相关文章

ASP.NET MVC Notes - 01

inetmgr 进入IIS ViewBag和ViewData在run-time的时候检查错误,View中的用法如下: @*ViewBag传递的是动态对象*@ @foreach (string item in ViewBag.listData) { <li>@item</li> } ----------------------------------------- @*ViewData传递的是Object,所以要转换类型*@ @foreach (string item in (Lis

Rust Notes - 01

普通的数组数据交换, let mut val = [1,2,3]; let t = val[0];    val[0] = val[1];    val[1] = t; it works...下面的也work: let mut val = ["1","2","3"]; let t = val[0];    val[0] = val[1];    val[1] = t; 但, let mut val = ["1".to_stri

我喜欢减肥我们来减肥吧

http://www.ebay.com/cln/honus.jyw4mvptb/cars/158313278016/2015.01.28.html http://www.ebay.com/cln/honus.jyw4mvptb/cars/158313282016/2015.01.28.html http://www.ebay.com/cln/honus.jyw4mvptb/cars/158313289016/2015.01.28.html http://www.ebay.com/cln/usli

百度回家看沙发沙发是减肥了卡斯加积分卡拉是减肥

http://www.ebay.com/cln/hpryu-caw8ke/cars/158056866019/2015.01.31 http://www.ebay.com/cln/xub.50x2l7cj/cars/158445650015/2015.01.31 http://www.ebay.com/cln/xub.50x2l7cj/cars/158445674015/2015.01.31 http://www.ebay.com/cln/xub.50x2l7cj/cars/1584456790

巢哑偕倥乇椭煞谙暗逞帕俸

IEEE Spectrum 杂志发布了一年一度的编程语言排行榜,这也是他们发布的第四届编程语言 Top 榜. 据介绍,IEEE Spectrum 的排序是来自 10 个重要线上数据源的综合,例如 Stack Overflow.Twitter.Reddit.IEEE Xplore.GitHub.CareerBuilder 等,对 48 种语言进行排行. 与其他排行榜不同的是,IEEE Spectrum 可以让读者自己选择参数组合时的权重,得到不同的排序结果.考虑到典型的 Spectrum 读者需求

我国第三代移动通信研究开发进展-尤肖虎200106

众所周知,数据科学是这几年才火起来的概念,而应运而生的数据科学家(data scientist)明显缺乏清晰的录取标准和工作内容.此次课程以<星际争霸II>回放文件分析为例,集中在IBM Cloud相关数据分析服务的应用.面对星际游戏爱好者希望提升技能的要求,我们使用IBM Data Science Experience中的jJupyter Notebooks来实现数据的可视化以及对数据进行深度分析,并最终存储到IBM Cloudant中.这是个介绍+动手实践的教程,参会者不仅将和讲师一起在线

pl/sql学习1——标量变量psahnh6S

为类型.不能用于表列的数据类型.范围为的子类型.自然数.为的子类型.具有约束为单精度浮点数.为变量赋值时.后面要加为双精度浮点数.为变量赋值时.后面要加.为数字总位数.为小数位数是的子类型.最大精度位是的子类型.最大精度位单精度浮点型是的子类型.最大精度位双精度浮点型定义精度为位的实数..定义为位的整数.变长字符串.最长测试变量数据!.定长字符串.最长测试变长二进制字符串物理存储的为类型...固定长度.个字节使用定义数据类型那个最小值:最大值:最小值:最大值:最小值:最大值:最小值:最大值:最小

[ExtJS5学习笔记]第三十节 sencha extjs 5表格gridpanel分组汇总

本文地址:http://blog.csdn.net/sushengmiyan/article/details/42240531 本文作者:sushengmiyan ------------------------------------------------------------------------------------------------------------------------------------ 本文以一个实际例子,使用了extjs的gridpanel中的分组统计显

[ExtJS5学习笔记]第二十三节 Extjs5中表格gridpanel的列格式设置

本文地址:http://blog.csdn.net/sushengmiyan/article/details/39665979 官方文档:http://docs.sencha.com/extjs/5.0/apidocs/#!/api/Ext.grid.column.Date 本文作者:sushengmiyan ----------------------------------------------------------------------------------------------