Commit 7f891998 authored by 杨奕's avatar 杨奕 Committed by GitHub

Merge pull request #815 from furybean/table-scroll

Table: support header mousewheel scroll.
parents 9e2fb770 496f3857
...@@ -96,6 +96,7 @@ ...@@ -96,6 +96,7 @@
import TableLayout from './table-layout'; import TableLayout from './table-layout';
import TableBody from './table-body'; import TableBody from './table-body';
import TableHeader from './table-header'; import TableHeader from './table-header';
import { mousewheel } from './util';
let tableIdSeed = 1; let tableIdSeed = 1;
...@@ -185,6 +186,20 @@ ...@@ -185,6 +186,20 @@
if (refs.rightFixedBodyWrapper) refs.rightFixedBodyWrapper.scrollTop = this.scrollTop; if (refs.rightFixedBodyWrapper) refs.rightFixedBodyWrapper.scrollTop = this.scrollTop;
}); });
mousewheel(headerWrapper, function(event) {
event.preventDefault();
});
mousewheel(headerWrapper, throttle(16, function(event) {
const deltaX = event.deltaX;
if (deltaX > 0) {
bodyWrapper.scrollLeft = bodyWrapper.scrollLeft + 10;
} else {
bodyWrapper.scrollLeft = bodyWrapper.scrollLeft - 10;
}
}));
if (this.fit) { if (this.fit) {
this.windowResizeListener = throttle(50, () => { this.windowResizeListener = throttle(50, () => {
if (this.$ready) this.doLayout(); if (this.$ready) this.doLayout();
......
...@@ -98,3 +98,11 @@ export const getColumnByCell = function(table, cell) { ...@@ -98,3 +98,11 @@ export const getColumnByCell = function(table, cell) {
} }
return null; return null;
}; };
const isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
export const mousewheel = function(element, callback) {
if (element && element.addEventListener) {
element.addEventListener(isFirefox ? 'DOMMouseScroll' : 'mousewheel', callback);
}
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment