Extjs存储插入roweditor

时间:2016-04-04 09:29:02

标签: extjs extjs6

设置: 我有一个带有roweditor插件的网格。在工具栏上,我有一个"添加新的"用于插入新行的按钮。 问题: 当我尝试添加新记录时,我的store.insert(0,rec),似乎没有在0索引上添加记录。

我的观点:

Ext.define("app.view.partners.Partners",{
extend: "Ext.grid.Panel",
alias: 'widget.partners',

requires: [
    "Admin.view.partners.PartnersController",
    "Admin.view.partners.PartnersModel"
],
height: 700,
controller: "partners",
viewModel: {
    type: "partners"
},
bind: {
    store: '{partners}'
},
title: "Partners List",
columns: [
    { header: 'id', dataIndex: 'id', hidden: true},
    { header: 'Partner', dataIndex: 'Partner', flex: 3,
        editor: {
            xtype: 'textfield',
            allowBlank: false
        }
    }

],

tbar: [{
    text: 'Add record',
    iconCls: 'fa fa-plus-square green',
    handler: 'onAddClick'
}],
selType: 'rowmodel',
plugins: [{

    ptype: 'rowediting',
    clicksToMoveEditor: 1,
    pluginId: 'partnersRowEditingPlugin',
    autoCancel: false,
    listeners: {
       edit: 'onEditClick',
       canceledit: function(rowEditing, context) {
            // Canceling editing of a locally added, unsaved record: remove it
            if (context.record.phantom) {
                context.store.remove(context.record);
            }
        }
    }
  },{ptype: 'bufferedrenderer'},
    {ptype: 'gridfilters'}
  ]
});

我的观点模型:

Ext.define('app.view.partners.PartnersModel', {
extend: 'Ext.app.ViewModel',
alias: 'viewmodel.partners',
stores: {
    partners:{
        model: 'app.model.Partners',
        storeId: 'partners',
        autoLoad: true,
        sorters: [{
            property: 'id',
            direction: 'DESC'
        }],
        proxy:{
            type: 'ajax',
            // load remote data using HTTP
            url: 'read.php',
            reader: {
                type: 'json',
                idProperty: 'id',
                rootProperty: 'data',
                totalProperty:'total'
            }
        } 
    }
}

});

并在viewcontroller中:

onAddClick: function(){
    var rec = new app.view.partners.PartnersModel({});
    //var rec = new new Admin.model.Partners({});

    this.isNewRecord = true;

    var store = this.getView().getStore();

    store.insert(0, rec);

    this.getView().getPlugin(controllerName + 'RowEditingPlugin').startEdit(0,0);
}

here is a console.log after store.insert(0,rec)

商店似乎插入了插件,但最后插入了它。我可以看到它在网格上添加为最后一条记录。

我不知道自己做错了什么。

0 个答案:

没有答案