javascript - How cell editing works with extjs store manager? - Stack Overflow

I have this example code from Sencha's websiteExt.onReady(function() { Ext.create('Ext.dat

I have this example code from Sencha's website

Ext.onReady(function() 
{   
    Ext.create('Ext.data.Store', {
        storeId:'simpsonsStore',
        fields:['name', 'email', 'phone'],
        data:{'items':[
            {"name":"Lisa", "email":"[email protected]", "phone":"555-111-1224"},
            {"name":"Bart", "email":"[email protected]", "phone":"555-222-1234"},
            {"name":"Homer", "email":"[email protected]", "phone":"555-222-1244"},
            {"name":"Marge", "email":"[email protected]", "phone":"555-222-1254"}
        ]},
        proxy: {
            type: 'memory',
            reader: {
                type: 'json',
                root: 'items'
            }
        }
    });

    Ext.create('Ext.grid.Panel', {
        title: 'Simpsons',
        store: Ext.data.StoreManager.lookup('simpsonsStore'),
        columns: [
            {header: 'Name',  dataIndex: 'name', editor: 'textfield'},
            {header: 'Email', dataIndex: 'email', flex:1,
                editor: {
                    xtype: 'textfield',
                    allowBlank: false
                }
            },
            {header: 'Phone', dataIndex: 'phone'}
        ],
        selType: 'cellmodel',
        plugins: 
        [{ 
            ptype: 'cellediting',
            clicksToEdit: 1
        }],
        height: 200,
        width: 400,
        renderTo: 'grid'
    });

});

This ptype: 'cellediting' plugin allows for inline cell editing by just clicking on textfield. I just cannot find any posts on how and where the changed value gets saved? How can I add a listener to a cell so that after each change I will be able to alert() the new value?

Thanks for any tips...

I have this example code from Sencha's website

Ext.onReady(function() 
{   
    Ext.create('Ext.data.Store', {
        storeId:'simpsonsStore',
        fields:['name', 'email', 'phone'],
        data:{'items':[
            {"name":"Lisa", "email":"[email protected]", "phone":"555-111-1224"},
            {"name":"Bart", "email":"[email protected]", "phone":"555-222-1234"},
            {"name":"Homer", "email":"[email protected]", "phone":"555-222-1244"},
            {"name":"Marge", "email":"[email protected]", "phone":"555-222-1254"}
        ]},
        proxy: {
            type: 'memory',
            reader: {
                type: 'json',
                root: 'items'
            }
        }
    });

    Ext.create('Ext.grid.Panel', {
        title: 'Simpsons',
        store: Ext.data.StoreManager.lookup('simpsonsStore'),
        columns: [
            {header: 'Name',  dataIndex: 'name', editor: 'textfield'},
            {header: 'Email', dataIndex: 'email', flex:1,
                editor: {
                    xtype: 'textfield',
                    allowBlank: false
                }
            },
            {header: 'Phone', dataIndex: 'phone'}
        ],
        selType: 'cellmodel',
        plugins: 
        [{ 
            ptype: 'cellediting',
            clicksToEdit: 1
        }],
        height: 200,
        width: 400,
        renderTo: 'grid'
    });

});

This ptype: 'cellediting' plugin allows for inline cell editing by just clicking on textfield. I just cannot find any posts on how and where the changed value gets saved? How can I add a listener to a cell so that after each change I will be able to alert() the new value?

Thanks for any tips...

Share Improve this question asked Jun 24, 2013 at 0:44 BrianBrian 5,0288 gold badges41 silver badges58 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

The record values are updated each time the editor is blurred (i.e. lose focus). Ext keeps track of fields in the records that have been modified, until you mit the changes (by syncing the store, for example).

To be notified that a field has been edited, use the edit event of the plugin. As you can see in the doc, you can install a listener for this event directly in the grid (no need to add the listener specifically to the plugin).

Edit

With your code, that would be something like this:

Ext.create('Ext.grid.Panel', {
    title: 'Simpsons',
    store: Ext.data.StoreManager.lookup('simpsonsStore'),
    columns: [
        {header: 'Name',  dataIndex: 'name', editor: 'textfield'},
        {header: 'Email', dataIndex: 'email', flex:1,
            editor: {
                xtype: 'textfield',
                allowBlank: false
            }
        },
        {header: 'Phone', dataIndex: 'phone'}
    ],
    selType: 'cellmodel',
    plugins: 
    [{ 
        ptype: 'cellediting',
        clicksToEdit: 1
    }],
    height: 200,
    width: 400,
    renderTo: 'grid',

    listeners: {
        edit: function(editor, e) {
            var record = e.record;

            alert(Ext.String.format(
                'The field "{0}" or record #{1} has been changed from {2} to {3}', 
                e.field, record.get('id'), e.originalValue, e.newValue
            ));

            alert('The following fields of the records are dirty: ' + Ext.Object.getKeys(record.modified).join(', '));
        }
    }
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745431920a4627429.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信