1

I display a grid, there are two rows in the grid. I have a button called "Copy", when user click on the Copy button, all the data from first row will copied, then paste it into second row.

The thing is there are already two rows displayed. I just need to copy all data of first row then paste into the content of second row

enter image description here

I am newbie and need a guidance how to implement this copy functionality.

1 Answer 1

1

In order to achieve this you need to copy the model (record) from the grid store's first record to the second record.

Check out this fiddle, this is the code (modern toolkit):

Ext.application({
    name: 'Copy / paste grid row',
    launch: function () {
        var store = Ext.create('Ext.data.Store', {
            fields: ['name', 'phone'],
            data: [{
                name: 'one',
                phone: 123,
            }, {
                name: null,
                phone: null
            }]
        });
        Ext.create({
            xtype: 'panel',
            tbar: [{
                text: 'Copy',
                handler: function (button, e) {
                    var firstRecord = store.getAt(0),
                        secondRecord = store.getAt(1);

                    secondRecord.copyFrom(firstRecord);
                    secondRecord.commit();
                }
            }],
            items: [{
                xtype: 'grid',
                title: 'Copy and paste grid row',
                store: store,
                columns: [{
                    text: 'name',
                    dataIndex: 'name',
                    flex: 1,
                }, {
                    text: 'phone',
                    dataIndex: 'phone',
                    flex: 1
                }],

            }],
            layout: 'fit',
            fullscreen: true,
            renderTo: Ext.getBody()
        });
    }
});

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.