Extjs5 GridPanel RowEditing Notes 01

來源:互聯網
上載者:User

標籤:

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;    }});

 

Extjs5 GridPanel RowEditing Notes 01

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.