Jump to content

to match js code grid to unigui


thiagopedro

Recommended Posts

how can I use this js code in unigui?

Ext.onReady(function () {
    var grid = Ext.widget({
        xtype: 'grid',
        height: 400,
        store: {
            fields: ['name', 'size', 'progress', 'status']
        },
        tbar: [{
            xtype: 'filefield',
            buttonOnly: true,
            width: 10,
            listeners: {
                render: function (s) {
                    s.fileInputEl.set({ multiple: 'multiple' });
                },
                change: function (s) {
                    Ext.each(s.fileInputEl.dom.files, function (f) {
                        var data = new FormData(),
                            rec = grid.store.add({ name: f.name, size: f.size, status: 'queued' })[0];
                        data.append('file', f);
                        Ext.Ajax.request({
                            url: '/upload/files',
                            rawData: data,
                            headers: { 'Content-Type': null }, //to use content type of FormData
                            progress: function (e) {
                                rec.set('progress', e.loaded / e.total);
                                rec.set('status', 'uploading...');
                                rec.commit();
                            },
                            success: function () {
                                rec.set('status', 'done');
                                rec.commit();
                            },
                            failure: function () {
                                rec.set('progress', 0);
                                rec.set('status', 'failed');
                                rec.commit();
                            }
                        });
                    });
                }
            }
        }],
        columns: [
            { text: 'Name', dataIndex: 'name', flex: 1 },
            { text: 'Status', dataIndex: 'status', width: 100 },
            {
                text: 'Progress', xtype: 'widgetcolumn', widget: {
                    xtype: 'progressbarwidget',
                    textTpl: [
                        '{percent:number("0")}%'
                    ]
                }, dataIndex: 'progress', width: 100
            },
            { text: 'Size', dataIndex: 'size', width: 100, renderer: Ext.util.Format.fileSize }
        ],
        renderTo: Ext.getBody()
    });
});

thanks for the help

Link to comment
Share on other sites

It is all available in unigui framework, except the progressbar that indicates the ‰ of the upload process, if you want to handle it manually you have also to handle server side code, anyway you may use the event 'viewready' in the clientevents of the grid and then for the specific column add your progress bar, also you may use the column renderer event to insert the progressbar.

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...