extjs给panel添加滚动条,如何在ExtJs中向面板添加水平滚动条?

I have created a panel using ExtJs.This panel is center item of a border layout viewport. I want to add a horizontal scrollbar into this panel.

The coding for this panel is given below.

var centerpanel = Ext.create('Ext.panel.Panel', {

region: 'center',

autoScroll: true,

name: 'mainpanel',

id: 'mainpanel',

items: [{

contentEl: 'center1'

}]

});

The coding for the viewport given below.

var viewport = Ext.create('Ext.Viewport', {

id: 'border-example',

layout: 'border',

items: [

{

region: 'south',

split: true,

height: 120,

minSize: 100,

maxSize: 200,

collapsible: true,

collapsed: true,

title: 'Notice',

margins: '2 2 2 2'

}, {

region: 'west',

id: 'west-panel',

title: ' Menu',

width: 150,

collapsible: true,

animCollapse: true,

margins: '0 0 0 5',

items: [{menu1},{menu2}]

},

centerpanel

]

});

I want to add horizontal scrollbar into "centerpanel". Please help me.

解决方案

I had to do this recently. There was a dynamic number of drag-n-drop grids (greater than 10) which needed to go onto a page side-by-side. These were all made accessible by scrolling horizontally with the bottom bar, mouse-wheel motion, or when dragging a record from one grid over to the far right or left side of the page (triggering the horizontal scroll). I used server side code to fill in the grids dynamically, but the horizontal scrolling was achieved in ExtJS.

Setting the panel's width: config option to greater than the width of the page and then using the following config options layout: { type: 'hbox', align: 'stretch' }, defaults: { flex : 1 } did the trick.

I had to add an ExtJS event handler on the panel to stop the default vertical scroll and enforce horizontal scroll because the grids inside my panel also had vertical scroll bars. These would consume the mousewheel event whenever the mouse was over them - it may not be needed if you don't use any other scrollbars inside your panel.

Here is what it looked like:

// PANEL TO HOUSE THE GRIDS

var displayPanel = Ext.create('Ext.Panel', {

id: 'displayPanel',

width: (/*server-side code here dynamically fills in total width based on number of grids...*/),

height: 200,

layout: {

type: 'hbox',

align: 'stretch',

padding: 5

},

renderTo: 'panel',

defaults: { flex : 1 }, //auto stretch

items: [/*server-side code here fills in the grids dynamically...*/>]

});

// HORIZONTAL SCROLL EVENT (ENFORCES HORIZONTAL SCROLL FOR MOUSEWHEEL)

displayPanel.body.on('mousewheel', function(e){

e.preventDefault();

movement = e.getWheelDeltas();

var body = Ext.getBody();

if (movement.y < 0)

{

body.scrollTo('left', (body.getScroll().left + 150));

}

else

{

body.scrollTo('left', (body.getScroll().left - 150));

}

});

// HORIZONTAL SCROLL WHEN RECORD IS DRAGGED FROM A GRID TO LEFT OR RIGHT SIDE OF SCREEN

function dragScroll(gridView){

if (dragging == true) {

var body = Ext.getBody();

var elRight = gridView.getEl().getRight();

var winRight = (body.getViewSize().width + body.getScroll().left);

var elLeft = gridView.getEl().getLeft();

var winLeft = body.getScroll().left

if (elRight > winRight - 10)

{

body.scrollTo('left', ((elRight - winRight) + winLeft + 40));

}

if (elLeft < winLeft + 10)

{

body.scrollTo('left', (elLeft - 40));

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值