Skip to content

Commit

Permalink
feat: Add support for RTL (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
deepeshgarg007 authored Apr 26, 2019
1 parent 67f9717 commit e014960
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/datatable.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class DataTable {

prepareDom() {
this.wrapper.innerHTML = `
<div class="datatable">
<div class="datatable" dir="${this.options.direction}">
<div class="dt-header"></div>
<div class="dt-scrollable"></div>
<div class="dt-footer"></div>
Expand Down
3 changes: 2 additions & 1 deletion src/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,6 @@ export default {
checkedRowStatus: true,
dynamicRowHeight: false,
pasteFromClipboard: false,
showTotalRow: false
showTotalRow: false,
direction: 'ltr'
};
9 changes: 6 additions & 3 deletions src/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,15 @@ export default class Style {
this._settingHeaderPosition = true;

requestAnimationFrame(() => {
const scrollLeft = e.target.scrollLeft;
const { scrollLeft, scrollWidth, clientWidth } = e.target;

let left = this.options.direction === 'rtl' ? scrollWidth - clientWidth - scrollLeft : -scrollLeft;

$.style(this.header, {
transform: `translateX(-${scrollLeft}px)`
transform: `translateX(${left}px)`
});
$.style(this.footer, {
transform: `translateX(-${scrollLeft}px)`
transform: `translateX(${left}px)`
});
this._settingHeaderPosition = false;
});
Expand Down

0 comments on commit e014960

Please sign in to comment.