Search code examples
extjsfile-uploadgridpanelfilefield

File field in any row of extjs grid panel


I want to create a grid panel and for any row added by user, insert a file, In other words one column in any row is a file field.

How can Id do this?

update:

Ext.define('FM.view.map.DefineCode', {
    extend: 'Ext.window.Window',
    title: 'Define Code',
    alias: 'widget.mmDefineCode',
    width: 600,
    modal: true,
    items: [{
        xtype: 'form',
        items: [{
            xtype: 'gridpanel',
            title: 'myGrid',
            store: 'DefineCode',
            columns: [
                {
                    text: 'Id',
                    xtype: 'rownumberer',
                    width: 20 
                }, {
                    text: 'Name',
                    dataIndex: 'name',
                    flex: 1, 
                    editor:{
                        xtype: 'textfield'
                    }
                }, {
                    text: 'File', 
                    dataIndex: 'filename', 
                    width: 200,
                    editor:{
                        xtype: 'filefield',
                        emptyText: 'Select your Icon',
                        name: 'photo-path',
                        buttonText: '',
                        flex: 1,
                        buttonConfig: {
                            iconCls: 'icon-upload-18x18'
                        },
                        listeners: {
                            change: function(e, ee, eee) {

                                var grid = this.up('grid');
                                var store = grid.getStore();
                                var newStore = Ext.create('FM.store.Path',{});
                                store.insert(store.data.items.length, newStore);
                            }
                        }
                    },
                }, { 
                    text: '', 
                    width: 40 
                }
            ],
            height: 200,
            width: 600,
            plugins: [
                Ext.create('Ext.grid.plugin.CellEditing', {
                    clicksToEdit: 1
                })
            ]}
        ],
    }],
    buttons: [{text: 'OK', action: 'OK'}],
    initComponent: function() {
        var me = this;


        Ext.apply(me, {});
        me.callParent(arguments);
    }
});

I want to any row select an Icon and then send any row(with Name and Filename variables) to server. How do this?


Solution

  • Try using defaultType to do that, like this below :

    defaultType: 'filefield',
        items: [{
            fieldLabel: 'Document 1',
            name: 'first',
            allowBlank: false
        }, {
            fieldLabel: 'Document 2',
            name: 'second',
            allowBlank: false
        }],
    

    Check this demo, I've created for you. I'm using CellEditing to edit the cell you click, test click in cell Name.