菜单滚动条在Extjs中无法正常工作

时间:2018-06-05 09:54:44

标签: javascript css extjs layout

我正在尝试在ExtJs中创建可滚动菜单

我面临的问题:

  1. 首次点击菜单按钮时滚动条不起作用(当滚动时似乎工作:false)

  2. 下次单击菜单时...菜单不再溢出..

  3. Fiddle showcasing the problem

    此外,

    必需的行为:

    This is the behavior I am trying to replicate:

    如果任何人有任何想法或遇到类似情况,请填写

    提前致谢

1 个答案:

答案 0 :(得分:0)

我知道问题是关于菜单滚动但是根据您的要求,您可以使用panel作为叠加层,并且可以使用grid在面板内使用checkboxmodel

您需要在设置按钮点击时使用showBy()方法。

  

带有覆盖面板的屏幕截图,可单击多个按钮。

enter image description here

在此 FIDDLE 中,我使用panelgrid创建了一个演示。希望这有助于/指导您实现您的要求。

CODE SNIPPET

Ext.application({
    name: 'Fiddle',

    launch: function () {
        //Common button click on setting button
        function onButtonClick(btn, e) {
            //If menu is alredy created for that button no need to create directly show or hide
            var myMenu = btn.myMenu;

            //If menu is not create then need to create
            if (!myMenu) {
                myMenu = btn.myMenu = Ext.create({
                    xtype: 'custommenu',
                    title: btn.getText()
                });
            }
            myMenu.isHidden() ? myMenu.showBy(btn, "bl") : myMenu.hide();
        }

        //Define common store for grid menu
        Ext.define('MenuStore', {
            extend: 'Ext.data.Store',
            alias: 'store.menustore',
            fields: ['text'],
            data: (() => {
                let data = [];
                for (let i = 65; i < 91; i++) {
                    data.push({
                        text: String.fromCharCode(i)
                    })
                }
                return data;
            })()
        })

        Ext.define('CustomMenuOverlay', {
            extend: 'Ext.panel.Panel',
            xtype: 'custommenu',
            hidden: true,
            tools: [{
                iconCls: 'x-fa fa-download'
            }, {
                type: 'refresh'
            }, {
                type: 'gear'
            }],
            width: 170,
            maxHeight: 200,
            floating: true,
            layout: 'vbox',
            items: [{
                xtype: 'grid',
                flex: 1,
                width: '100%',
                height: 200,
                selModel: {
                    checkOnly: false,
                    mode: 'SIMPLE'
                },
                selType: 'checkboxmodel',
                store: {
                    type: 'menustore'
                },
                columns: [{
                    dataIndex: 'text',
                    flex: 1
                }]
            }],

            bbar: [{
                text: 'Apply',
                width: '100%',
                itemId: 'apply',
                handler: function (btn) {
                    //On appy button click you put your logic whatever you need
                    //You can get menu using up selector with {custommenu}
                    var myMenu = btn.up('custommenu');
                    myMenu.hide();
                    console.log(myMenu.down('grid').getSelection())
                }
            }]
        });

        //create grid panel
        Ext.create('Ext.grid.Panel', {
            title: 'Support',
            store: {
                fields: ['firstName', 'Surname'],
                data: [{
                    Rank: 30,
                    firstName: 'Mihir',
                    Surname: "Kothari",
                    FullName: "Z Kothari Mihir"
                }, {
                    Rank: 20,
                    firstName: 'Parv',
                    Surname: "Kothari",
                    FullName: "X Kothari Parv"
                }, {
                    Rank: 10,
                    firstName: 'Reena',
                    Surname: "Kothari",
                    FullName: "Y Kothari Reena"
                }]
            },

            columns: [{
                text: 'Surname',
                dataIndex: 'Surname'
            }, {
                text: 'FirstName',
                dataIndex: 'firstName'
            }, {
                text: 'Rank',
                dataIndex: 'Rank'
            }],

            bbar: [{
                text: 'settings',
                handler: onButtonClick
            }, '->', {
                text: 'settings1',
                handler: onButtonClick
            }, '->', {
                text: 'settings2',
                handler: onButtonClick
            }, '->', {
                text: 'settings3',
                handler: onButtonClick
            }, '->'],
            renderTo: Ext.getBody()
        });

    }
});