How to display filefield in the grid cell in ExtJS

1.6k views Asked by At

I have created a grid on the form and I am displaying records dynamically, and I am using cell editor to edit the comments column and in another column using filefield to browse a file and displaying its full path in the attachment column. See the code that I am using:

                  {
                        xtype: 'container',
                        flex: 1,
                        layout: {
                            type: 'fit'
                        },
                        items: [
                            {
                                xtype: 'grid',
                                itemId: 'myAttachGrid',
                                reference: 'myAttachGrid ',
                                store: Ext.create('JSSample.store.attach.MyAttachGrid'),
                                multiSelect: true,
                                autoScroll: true,
                                columnWidth: 1,
                                editable: true,
                                columnLines: true,
                                plugins: [
                                    Ext.create('Ext.grid.plugin.CellEditing', {
                                        clicksToMoveEditor: 1,
                                        autoCancel: false
                                    })
                                ],
                                columns: [
                                    {
                                        header: 'File', dataIndex: 'Attachments', width: '40%'
                                    },                                        
                                    {
                                        header: '',
                                        dataIndex: '',
                                        width: '10%',
                                        hideable: true,
                                        editor: {
                                            xtype: 'filefield',
                                            labelWidth: 50,
                                            msgTarget: 'side',
                                            buttonOnly: true,
                                            anchor: '100%',                                                
                                            buttonText: '...',
                                            listeners: {
                                                change: function (fld, value) {
                                                    alert(value.replace(/C:\\fakepath\\/g, ''));
                                                }
                                            }
                                        }
                                    },                                      

                                    {
                                        header: 'Comments', dataIndex: 'Comments', width: '50%', editor: 'textfield'
                                    }
                                ]
                            }
                        ]
                    }

After loading the grid records are displaying dynamically like this:

enter image description here

Now, my problem is filefield is displaying after when we double click on the cell. [below is the screenshot]:

enter image description here

So, I want to visible the filefield with the records [without double click on the cell].

1

There are 1 answers

1
Sergey Novikov On

As @alexander mentioned in the comment, with ExtJS 6 you can use Ext.grid.column.Widget to add file field to your grid.

Check this fiddle for example.