日期:2014-05-16  浏览次数:20362 次

Extjs4 表格式例子(2)

ExtJs Grid: "Remove Selected Record" Toolbar Button

Ext.onReady(function () {
    Ext.define('Ext.ux.DeleteButton', {
        extend: 'Ext.button.Button',
        alias: 'widget.delbutton',
        text: 'Remove Selected Record',
        handler: function () {
            var grid = this.up('grid');
            if (grid) {
                var sm = grid.getSelectionModel();
                var rs = sm.getSelection();
                if (!rs.length) {
                    Ext.Msg.alert('Info', 'No Records Selected');
                    return;
                }
                Ext.Msg.confirm('Remove Record', 'Are you sure?', function (button) {
                    if (button == 'yes') {
                        grid.store.remove(rs[0]);
                    }
                });
            }
        }
    });
 
    Ext.create('Ext.grid.Panel', {
        title: 'Simpsons',
        width: 500,
        tbar: [{ xtype: 'delbutton'}],
        store: {
            fields: ['name', 'email', 'phone'],
            data: [
                { 'name': 'Lisa', "email": "lisa@simpsons.com", "phone": "555-111-1224" },
                { 'name': 'Bart', "email": "bart@simpsons.com", "phone": "555-222-1234" },
                { 'name': 'Homer', "email": "home@simpsons.com", "phone": "555-222-1244" }
            ]
        },
        columns: [
            { header: 'Name', dataIndex: 'name' },
            { header: 'Email', dataIndex: 'email', flex: 1 },
            { header: 'Phone', dataIndex: 'phone' }
        ],
        renderTo: 'output'
    });
});

How To Make Every Grid Able To Create It's Own Store Instance? - Part 2

Ext.onReady(function () {
    Ext.define('App.MyStore', {
        extend: 'Ext.data.Store',
        fields: ['name', 'email', 'phone'],
        data: [
            { 'name': 'Lisa', "email": "lisa@simpsons.com", "phone": "555-111-1224" },
            { 'name': 'Bart', "email": "bart@simpsons.com", "phone": "555-222-1234" },
            { 'name': 'Homer', "email": "home@simpsons.com", "phone": "555-222-1244" }
        ]
    });
    Ext.define('App.MyForm', {
        extend: 'Ext.window.Window',
        alias: 'widget.myform',
        title: 'Simpsons',
        width: 500,
        layout: 'fit',
        initComponent: function () {
            var store = Ext.create('App.MyStore');
            this.items = [{
                xtype: 'grid',
                store: store,
                columns: [
                    { header: 'Name', dataIndex: 'name' },
                    { header: 'Email', dataIndex: 'email', flex: 1 },
                    { header: 'Phone', dataIndex: 'phone' }
                ]
            }];
            this.callParent(arguments);
        }
    });
    Ext.widget('button', {
        text: 'First Test Grid',
        renderTo: 'output',
        handler: function () {
            Ext.widget('myform', {
                title: 'First Test Grid',
                border: false,
                autoShow: true
            });
        }
    });
    Ext.widget('button', {
        text: 'Second Test Grid',
        renderTo: 'output',
        handler: function () {
            Ext.widget('myform', {
                title: 'Second Test Grid',
                border: false,
                autoShow: true
            });
        }
    });
友情链接: 爱易网 云虚拟主机技术 云服务器技术 程序设计技术 开发网站 APP开发教程
Copyright © 2013-2024 爱易网页 当前在线:178人  网站在10分39秒内访问总人数:2784人 当前 12.18%  粤ICP备18100884号-2