Merge branch 'master' into add-tooltip-on-filter
This commit is contained in:
commit
5db24187e6
@ -35,7 +35,6 @@
|
|||||||
"block-scoped-var": 2,
|
"block-scoped-var": 2,
|
||||||
"brace-style": [2, "1tbs", { "allowSingleLine": true }],
|
"brace-style": [2, "1tbs", { "allowSingleLine": true }],
|
||||||
"camelcase": [2, { "properties": "always" }],
|
"camelcase": [2, { "properties": "always" }],
|
||||||
"comma-dangle": [2, "never"],
|
|
||||||
"comma-spacing": [2, { "before": false, "after": true }],
|
"comma-spacing": [2, { "before": false, "after": true }],
|
||||||
"comma-style": [2, "last"],
|
"comma-style": [2, "last"],
|
||||||
"complexity": 0,
|
"complexity": 0,
|
||||||
|
|||||||
18
.github/workflows/test-and-release.yml
vendored
18
.github/workflows/test-and-release.yml
vendored
@ -4,17 +4,19 @@ on:
|
|||||||
branches:
|
branches:
|
||||||
- master
|
- master
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test-and-release:
|
||||||
runs-on: ubuntu-16.04
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- uses: actions/setup-node@v1
|
- name: Lint, build and test
|
||||||
|
uses: cypress-io/github-action@v2
|
||||||
with:
|
with:
|
||||||
node-version: '12'
|
build: yarn lint-and-build
|
||||||
- run: yarn install --frozen-lockfile
|
start: yarn cy:server
|
||||||
- run: yarn lint
|
record: true
|
||||||
- run: yarn build
|
env:
|
||||||
- run: yarn test
|
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
- name: Release
|
- name: Release
|
||||||
env:
|
env:
|
||||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
|
|||||||
18
.github/workflows/test-pull-request.yml
vendored
18
.github/workflows/test-pull-request.yml
vendored
@ -1,14 +1,16 @@
|
|||||||
name: Test Pull Request
|
name: Test Pull Request
|
||||||
on: pull_request
|
on: pull_request
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test-pull-request:
|
||||||
runs-on: ubuntu-16.04
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- uses: actions/setup-node@v1
|
- name: Lint, build and test
|
||||||
|
uses: cypress-io/github-action@v2
|
||||||
with:
|
with:
|
||||||
node-version: '12'
|
build: yarn lint-and-build
|
||||||
- run: yarn install --frozen-lockfile
|
start: yarn cy:server
|
||||||
- run: yarn lint
|
record: true
|
||||||
- run: yarn build
|
env:
|
||||||
- run: yarn test
|
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
{
|
{
|
||||||
"baseUrl": "http://localhost:8989"
|
"baseUrl": "http://localhost:8989",
|
||||||
|
"projectId": "2nsyux"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,7 +32,7 @@ describe('Cell', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('edit cell', function () {
|
it('edit cell', function () {
|
||||||
cy.getCell(4, 1).dblclick();
|
cy.getCell(4, 1).dblclick({ force: true });
|
||||||
cy.getCell(4, 1).find('input').click();
|
cy.getCell(4, 1).find('input').click();
|
||||||
cy.focused().type('{selectall}{del}Test{enter}');
|
cy.focused().type('{selectall}{del}Test{enter}');
|
||||||
cy.getCell(4, 1).contains('Test');
|
cy.getCell(4, 1).contains('Test');
|
||||||
|
|||||||
@ -14,36 +14,36 @@ describe('Inline Filters', function () {
|
|||||||
cy.getCell(4, 0).click().type('{ctrl}f');
|
cy.getCell(4, 0).click().type('{ctrl}f');
|
||||||
|
|
||||||
cy.get('@filterInput4').type('edin');
|
cy.get('@filterInput4').type('edin');
|
||||||
cy.get('.dt-row[data-row-index=0]').should('be.visible');
|
cy.get('.dt-row-0').should('be.visible');
|
||||||
cy.get('.dt-row[data-row-index=1]').should('not.be.visible');
|
cy.get('.dt-row-1').should('not.exist');
|
||||||
cy.get('@filterInput4').clear();
|
cy.get('@filterInput4').clear();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('simple number filter', function () {
|
it('simple number filter', function () {
|
||||||
cy.get('@filterInput5').type('2360');
|
cy.get('@filterInput5').type('2360');
|
||||||
cy.get('.dt-row[data-row-index=8]').should('be.visible');
|
cy.get('.dt-row[data-row-index=8]').should('be.visible');
|
||||||
cy.get('.dt-row[data-row-index=15]').should('not.be.visible');
|
cy.get('.dt-row[data-row-index=15]').should('not.exist');
|
||||||
cy.get('.dt-row[data-row-index=22]').should('not.be.visible');
|
cy.get('.dt-row[data-row-index=22]').should('not.exist');
|
||||||
cy.get('@filterInput5').clear();
|
cy.get('@filterInput5').clear();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('greater than', function () {
|
it('greater than', function () {
|
||||||
cy.get('@filterInput5').type('> 6000');
|
cy.get('@filterInput5').type('> 6000');
|
||||||
cy.get('.dt-row[data-row-index=0]').should('not.be.visible');
|
cy.get('.dt-row[data-row-index=0]').should('not.exist');
|
||||||
cy.get('.dt-row[data-row-index=3]').should('be.visible');
|
cy.get('.dt-row[data-row-index=3]').should('be.visible');
|
||||||
cy.get('@filterInput5').clear();
|
cy.get('@filterInput5').clear();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('less than', function () {
|
it('less than', function () {
|
||||||
cy.get('@filterInput5').type('< 2000');
|
cy.get('@filterInput5').type('< 2000');
|
||||||
cy.get('.dt-row[data-row-index=0]').should('not.be.visible');
|
cy.get('.dt-row[data-row-index=0]').should('not.exist');
|
||||||
cy.get('.dt-row[data-row-index=51]').should('be.visible');
|
cy.get('.dt-row[data-row-index=51]').should('be.visible');
|
||||||
cy.get('@filterInput5').clear();
|
cy.get('@filterInput5').clear();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('range', function () {
|
it('range', function () {
|
||||||
cy.get('@filterInput5').type(' 2000: 5000');
|
cy.get('@filterInput5').type(' 2000: 5000');
|
||||||
cy.get('.dt-row[data-row-index=4]').should('not.be.visible');
|
cy.get('.dt-row[data-row-index=4]').should('not.exist');
|
||||||
cy.get('.dt-row[data-row-index=5]').should('be.visible');
|
cy.get('.dt-row[data-row-index=5]').should('be.visible');
|
||||||
cy.get('@filterInput5').clear();
|
cy.get('@filterInput5').clear();
|
||||||
});
|
});
|
||||||
@ -58,16 +58,15 @@ describe('Inline Filters', function () {
|
|||||||
cy.get('@filterInput4').type('to');
|
cy.get('@filterInput4').type('to');
|
||||||
cy.get('@filterInput5').type('54');
|
cy.get('@filterInput5').type('54');
|
||||||
|
|
||||||
cy.get('.dt-row[data-row-index=0]').should('be.visible');
|
|
||||||
cy.get('.dt-row[data-row-index=4]').should('be.visible');
|
cy.get('.dt-row[data-row-index=4]').should('be.visible');
|
||||||
cy.get('.dt-row[data-row-index=1]').should('not.be.visible');
|
cy.get('.dt-row[data-row-index=1]').should('not.exist');
|
||||||
cy.get('@filterInput4').clear();
|
cy.get('@filterInput4').clear();
|
||||||
cy.get('@filterInput5').clear();
|
cy.get('@filterInput5').clear();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('greater than for string type filters', function () {
|
it('greater than for string type filters', function () {
|
||||||
cy.get('@filterInput6').type('> 01/07/2011');
|
cy.get('@filterInput6').type('> 01/07/2011');
|
||||||
cy.get('.dt-row[data-row-index=0]').should('not.be.visible');
|
cy.get('.dt-row[data-row-index=0]').should('not.exist');
|
||||||
cy.get('.dt-row[data-row-index=1]').should('be.visible');
|
cy.get('.dt-row[data-row-index=1]').should('be.visible');
|
||||||
cy.get('.dt-row[data-row-index=3]').should('be.visible');
|
cy.get('.dt-row[data-row-index=3]').should('be.visible');
|
||||||
cy.get('.dt-row[data-row-index=5]').should('be.visible');
|
cy.get('.dt-row[data-row-index=5]').should('be.visible');
|
||||||
|
|||||||
15
index.html
15
index.html
@ -18,7 +18,8 @@
|
|||||||
|
|
||||||
<body>
|
<body>
|
||||||
<h1>Frappé DataTable</h1>
|
<h1>Frappé DataTable</h1>
|
||||||
<button onclick="datatable.render()">Refresh</button>
|
<button onclick="datatable.render()">Render Table</button>
|
||||||
|
<button onclick="datatable.refresh()">Refresh Data</button>
|
||||||
<button onclick="switchToTreeView()" data-action="treeview">TreeView</button>
|
<button onclick="switchToTreeView()" data-action="treeview">TreeView</button>
|
||||||
<label>
|
<label>
|
||||||
<input type="checkbox" id="input-large-data" />
|
<input type="checkbox" id="input-large-data" />
|
||||||
@ -188,6 +189,18 @@
|
|||||||
dynamicRowHeight: true,
|
dynamicRowHeight: true,
|
||||||
treeView: treeView,
|
treeView: treeView,
|
||||||
showTotalRow: true,
|
showTotalRow: true,
|
||||||
|
// direction: 'rtl',
|
||||||
|
// language: 'myLang',
|
||||||
|
// translations: {
|
||||||
|
// myLang: {
|
||||||
|
// "Sort Ascending": "Sort low to high",
|
||||||
|
// "{count} cells copied": {
|
||||||
|
// "1": "1 cell was copied",
|
||||||
|
// "2": "2 cells were copied",
|
||||||
|
// "default": "Many cells were copied"
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// },
|
||||||
// filterRows(keyword, cells, colIndex) {
|
// filterRows(keyword, cells, colIndex) {
|
||||||
// return cells
|
// return cells
|
||||||
// .filter(cell => cell.content.includes(keyword))
|
// .filter(cell => cell.content.includes(keyword))
|
||||||
|
|||||||
@ -17,6 +17,7 @@
|
|||||||
"travis-deploy-once": "travis-deploy-once",
|
"travis-deploy-once": "travis-deploy-once",
|
||||||
"semantic-release": "semantic-release",
|
"semantic-release": "semantic-release",
|
||||||
"lint": "eslint src",
|
"lint": "eslint src",
|
||||||
|
"lint-and-build": "yarn lint && yarn build",
|
||||||
"commit": "npx git-cz"
|
"commit": "npx git-cz"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
@ -26,7 +27,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"autoprefixer": "^9.0.0",
|
"autoprefixer": "^9.0.0",
|
||||||
"chai": "3.5.0",
|
"chai": "3.5.0",
|
||||||
"cypress": "3.0.1",
|
"cypress": "^9.2.0",
|
||||||
"cz-conventional-changelog": "^2.1.0",
|
"cz-conventional-changelog": "^2.1.0",
|
||||||
"deepmerge": "^2.0.1",
|
"deepmerge": "^2.0.1",
|
||||||
"eslint": "^5.0.1",
|
"eslint": "^5.0.1",
|
||||||
|
|||||||
@ -133,7 +133,10 @@ export default class CellManager {
|
|||||||
bindCopyCellContents() {
|
bindCopyCellContents() {
|
||||||
this.keyboard.on('ctrl+c', () => {
|
this.keyboard.on('ctrl+c', () => {
|
||||||
const noOfCellsCopied = this.copyCellContents(this.$focusedCell, this.$selectionCursor);
|
const noOfCellsCopied = this.copyCellContents(this.$focusedCell, this.$selectionCursor);
|
||||||
const message = `${noOfCellsCopied} cell${noOfCellsCopied > 1 ? 's' : ''} copied`;
|
const message = this.instance.translate('{count} cells copied', {
|
||||||
|
count: noOfCellsCopied
|
||||||
|
});
|
||||||
|
|
||||||
if (noOfCellsCopied) {
|
if (noOfCellsCopied) {
|
||||||
this.instance.showToastMessage(message, 2);
|
this.instance.showToastMessage(message, 2);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -174,7 +174,11 @@ export default class ColumnManager {
|
|||||||
|
|
||||||
const onMouseMove = (e) => {
|
const onMouseMove = (e) => {
|
||||||
if (!isDragging) return;
|
if (!isDragging) return;
|
||||||
const finalWidth = startWidth + (e.pageX - startX);
|
let delta = e.pageX - startX;
|
||||||
|
if (this.options.direction === 'rtl') {
|
||||||
|
delta = -1 * delta;
|
||||||
|
}
|
||||||
|
const finalWidth = startWidth + delta;
|
||||||
const {
|
const {
|
||||||
colIndex
|
colIndex
|
||||||
} = $.data($resizingCell);
|
} = $.data($resizingCell);
|
||||||
|
|||||||
@ -6,7 +6,8 @@ import RowManager from './rowmanager';
|
|||||||
import BodyRenderer from './body-renderer';
|
import BodyRenderer from './body-renderer';
|
||||||
import Style from './style';
|
import Style from './style';
|
||||||
import Keyboard from './keyboard';
|
import Keyboard from './keyboard';
|
||||||
import DEFAULT_OPTIONS from './defaults';
|
import TranslationManager from './translationmanager';
|
||||||
|
import getDefaultOptions from './defaults';
|
||||||
|
|
||||||
let defaultComponents = {
|
let defaultComponents = {
|
||||||
DataManager,
|
DataManager,
|
||||||
@ -31,6 +32,8 @@ class DataTable {
|
|||||||
throw new Error('Invalid argument given for `wrapper`');
|
throw new Error('Invalid argument given for `wrapper`');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.initializeTranslations(options);
|
||||||
|
this.setDefaultOptions();
|
||||||
this.buildOptions(options);
|
this.buildOptions(options);
|
||||||
this.prepare();
|
this.prepare();
|
||||||
this.initializeComponents();
|
this.initializeComponents();
|
||||||
@ -41,23 +44,36 @@ class DataTable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initializeTranslations(options) {
|
||||||
|
this.language = options.language || 'en';
|
||||||
|
this.translationManager = new TranslationManager(this.language);
|
||||||
|
|
||||||
|
if (options.translations) {
|
||||||
|
this.translationManager.addTranslations(options.translations);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setDefaultOptions() {
|
||||||
|
this.DEFAULT_OPTIONS = getDefaultOptions(this);
|
||||||
|
}
|
||||||
|
|
||||||
buildOptions(options) {
|
buildOptions(options) {
|
||||||
this.options = this.options || {};
|
this.options = this.options || {};
|
||||||
|
|
||||||
this.options = Object.assign(
|
this.options = Object.assign(
|
||||||
{}, DEFAULT_OPTIONS,
|
{}, this.DEFAULT_OPTIONS,
|
||||||
this.options || {}, options
|
this.options || {}, options
|
||||||
);
|
);
|
||||||
|
|
||||||
options.headerDropdown = options.headerDropdown || [];
|
options.headerDropdown = options.headerDropdown || [];
|
||||||
this.options.headerDropdown = [
|
this.options.headerDropdown = [
|
||||||
...DEFAULT_OPTIONS.headerDropdown,
|
...this.DEFAULT_OPTIONS.headerDropdown,
|
||||||
...options.headerDropdown
|
...options.headerDropdown
|
||||||
];
|
];
|
||||||
|
|
||||||
// custom user events
|
// custom user events
|
||||||
this.events = Object.assign(
|
this.events = Object.assign(
|
||||||
{}, DEFAULT_OPTIONS.events,
|
{}, this.DEFAULT_OPTIONS.events,
|
||||||
this.options.events || {},
|
this.options.events || {},
|
||||||
options.events || {}
|
options.events || {}
|
||||||
);
|
);
|
||||||
@ -243,6 +259,10 @@ class DataTable {
|
|||||||
console.log.apply(console, arguments);
|
console.log.apply(console, arguments);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
translate(str, args) {
|
||||||
|
return this.translationManager.translate(str, args);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DataTable.instances = 0;
|
DataTable.instances = 0;
|
||||||
|
|||||||
128
src/defaults.js
128
src/defaults.js
@ -1,71 +1,73 @@
|
|||||||
import filterRows from './filterRows';
|
import filterRows from './filterRows';
|
||||||
import icons from './icons';
|
import icons from './icons';
|
||||||
|
|
||||||
export default {
|
export default function getDefaultOptions(instance) {
|
||||||
columns: [],
|
return {
|
||||||
data: [],
|
columns: [],
|
||||||
dropdownButton: icons.chevronDown,
|
data: [],
|
||||||
headerDropdown: [
|
dropdownButton: icons.chevronDown,
|
||||||
{
|
headerDropdown: [
|
||||||
label: 'Sort Ascending',
|
{
|
||||||
action: function (column) {
|
label: instance.translate('Sort Ascending'),
|
||||||
this.sortColumn(column.colIndex, 'asc');
|
action: function (column) {
|
||||||
|
this.sortColumn(column.colIndex, 'asc');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: instance.translate('Sort Descending'),
|
||||||
|
action: function (column) {
|
||||||
|
this.sortColumn(column.colIndex, 'desc');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: instance.translate('Reset sorting'),
|
||||||
|
action: function (column) {
|
||||||
|
this.sortColumn(column.colIndex, 'none');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: instance.translate('Remove column'),
|
||||||
|
action: function (column) {
|
||||||
|
this.removeColumn(column.colIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
events: {
|
||||||
|
onRemoveColumn(column) {},
|
||||||
|
onSwitchColumn(column1, column2) {},
|
||||||
|
onSortColumn(column) {},
|
||||||
|
onCheckRow(row) {},
|
||||||
|
onDestroy() {}
|
||||||
},
|
},
|
||||||
{
|
hooks: {
|
||||||
label: 'Sort Descending',
|
columnTotal: null
|
||||||
action: function (column) {
|
|
||||||
this.sortColumn(column.colIndex, 'desc');
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
sortIndicator: {
|
||||||
label: 'Reset sorting',
|
asc: '↑',
|
||||||
action: function (column) {
|
desc: '↓',
|
||||||
this.sortColumn(column.colIndex, 'none');
|
none: ''
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
overrideComponents: {
|
||||||
label: 'Remove column',
|
// ColumnManager: CustomColumnManager
|
||||||
action: function (column) {
|
},
|
||||||
this.removeColumn(column.colIndex);
|
filterRows: filterRows,
|
||||||
}
|
freezeMessage: '',
|
||||||
}
|
getEditor: null,
|
||||||
],
|
serialNoColumn: true,
|
||||||
events: {
|
checkboxColumn: false,
|
||||||
onRemoveColumn(column) {},
|
clusterize: true,
|
||||||
onSwitchColumn(column1, column2) {},
|
logs: false,
|
||||||
onSortColumn(column) {},
|
layout: 'fixed', // fixed, fluid, ratio
|
||||||
onCheckRow(row) {},
|
noDataMessage: instance.translate('No Data'),
|
||||||
onDestroy() {}
|
cellHeight: 40,
|
||||||
},
|
minimumColumnWidth: 30,
|
||||||
hooks: {
|
inlineFilters: false,
|
||||||
columnTotal: null
|
treeView: false,
|
||||||
},
|
checkedRowStatus: true,
|
||||||
sortIndicator: {
|
dynamicRowHeight: false,
|
||||||
asc: '↑',
|
pasteFromClipboard: false,
|
||||||
desc: '↓',
|
showTotalRow: false,
|
||||||
none: ''
|
direction: 'ltr',
|
||||||
},
|
disableReorderColumn: false
|
||||||
overrideComponents: {
|
};
|
||||||
// ColumnManager: CustomColumnManager
|
|
||||||
},
|
|
||||||
filterRows: filterRows,
|
|
||||||
freezeMessage: '',
|
|
||||||
getEditor: null,
|
|
||||||
serialNoColumn: true,
|
|
||||||
checkboxColumn: false,
|
|
||||||
clusterize: true,
|
|
||||||
logs: false,
|
|
||||||
layout: 'fixed', // fixed, fluid, ratio
|
|
||||||
noDataMessage: 'No Data',
|
|
||||||
cellHeight: 40,
|
|
||||||
minimumColumnWidth: 30,
|
|
||||||
inlineFilters: false,
|
|
||||||
treeView: false,
|
|
||||||
checkedRowStatus: true,
|
|
||||||
dynamicRowHeight: false,
|
|
||||||
pasteFromClipboard: false,
|
|
||||||
showTotalRow: false,
|
|
||||||
direction: 'ltr',
|
|
||||||
disableReorderColumn: false
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -133,7 +133,10 @@ export default class RowManager {
|
|||||||
const checkedRows = this.getCheckedRows();
|
const checkedRows = this.getCheckedRows();
|
||||||
const count = checkedRows.length;
|
const count = checkedRows.length;
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
this.bodyRenderer.showToastMessage(`${count} row${count > 1 ? 's' : ''} selected`);
|
let message = this.instance.translate('{count} rows selected', {
|
||||||
|
count: count
|
||||||
|
});
|
||||||
|
this.bodyRenderer.showToastMessage(message);
|
||||||
} else {
|
} else {
|
||||||
this.bodyRenderer.clearToastMessage();
|
this.bodyRenderer.clearToastMessage();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -164,6 +164,11 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.datatable[dir=rtl] .dt-cell__resize-handle {
|
||||||
|
right: unset;
|
||||||
|
left: -3px;
|
||||||
|
}
|
||||||
|
|
||||||
.icon-open, .icon-close {
|
.icon-open, .icon-close {
|
||||||
width: 16px;
|
width: 16px;
|
||||||
height: 16px;
|
height: 16px;
|
||||||
|
|||||||
@ -192,11 +192,6 @@ export default class Style {
|
|||||||
|
|
||||||
let naturalWidth = $.style($('.dt-cell__content', $cell), 'width');
|
let naturalWidth = $.style($('.dt-cell__content', $cell), 'width');
|
||||||
|
|
||||||
if (column.id === '_rowIndex') {
|
|
||||||
naturalWidth = this.getRowIndexColumnWidth();
|
|
||||||
column.width = naturalWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof naturalWidth === 'number' && naturalWidth >= column.naturalWidth) {
|
if (typeof naturalWidth === 'number' && naturalWidth >= column.naturalWidth) {
|
||||||
column.naturalWidth = naturalWidth;
|
column.naturalWidth = naturalWidth;
|
||||||
} else {
|
} else {
|
||||||
@ -245,6 +240,9 @@ export default class Style {
|
|||||||
if (!column.width) {
|
if (!column.width) {
|
||||||
column.width = column.naturalWidth;
|
column.width = column.naturalWidth;
|
||||||
}
|
}
|
||||||
|
if (column.id === '_rowIndex') {
|
||||||
|
column.width = this.getRowIndexColumnWidth();
|
||||||
|
}
|
||||||
if (column.width < this.options.minimumColumnWidth) {
|
if (column.width < this.options.minimumColumnWidth) {
|
||||||
column.width = this.options.minimumColumnWidth;
|
column.width = this.options.minimumColumnWidth;
|
||||||
}
|
}
|
||||||
|
|||||||
30
src/translationmanager.js
Normal file
30
src/translationmanager.js
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import { format } from './utils';
|
||||||
|
import getTranslations from './translations';
|
||||||
|
|
||||||
|
export default class TranslationManager {
|
||||||
|
constructor(language) {
|
||||||
|
this.language = language;
|
||||||
|
this.translations = getTranslations();
|
||||||
|
}
|
||||||
|
|
||||||
|
addTranslations(translations) {
|
||||||
|
this.translations = Object.assign(this.translations, translations);
|
||||||
|
}
|
||||||
|
|
||||||
|
translate(sourceText, args) {
|
||||||
|
let translation = (this.translations[this.language] &&
|
||||||
|
this.translations[this.language][sourceText]) || sourceText;
|
||||||
|
|
||||||
|
if (typeof translation === 'object') {
|
||||||
|
translation = args && args.count ?
|
||||||
|
this.getPluralizedTranslation(translation, args.count) :
|
||||||
|
sourceText;
|
||||||
|
}
|
||||||
|
|
||||||
|
return format(translation, args || {});
|
||||||
|
}
|
||||||
|
|
||||||
|
getPluralizedTranslation(translations, count) {
|
||||||
|
return translations[count] || translations['default'];
|
||||||
|
}
|
||||||
|
};
|
||||||
15
src/translations/de.json
Normal file
15
src/translations/de.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"Sort Ascending": "Aufsteigend sortieren",
|
||||||
|
"Sort Descending": "Absteigend sortieren",
|
||||||
|
"Reset sorting": "Sortierung zurücksetzen",
|
||||||
|
"Remove column": "Spalte entfernen",
|
||||||
|
"No Data": "Keine Daten",
|
||||||
|
"{count} cells copied": {
|
||||||
|
"1": "{count} Zelle kopiert",
|
||||||
|
"default": "{count} Zellen kopiert"
|
||||||
|
},
|
||||||
|
"{count} rows selected": {
|
||||||
|
"1": "{count} Zeile ausgewählt",
|
||||||
|
"default": "{count} Zeilen ausgewählt"
|
||||||
|
}
|
||||||
|
}
|
||||||
15
src/translations/en.json
Normal file
15
src/translations/en.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"Sort Ascending": "Sort Ascending",
|
||||||
|
"Sort Descending": "Sort Descending",
|
||||||
|
"Reset sorting": "Reset sorting",
|
||||||
|
"Remove column": "Remove column",
|
||||||
|
"No Data": "No Data",
|
||||||
|
"{count} cells copied": {
|
||||||
|
"1": "{count} cell copied",
|
||||||
|
"default": "{count} cells copied"
|
||||||
|
},
|
||||||
|
"{count} rows selected": {
|
||||||
|
"1": "{count} row selected",
|
||||||
|
"default": "{count} rows selected"
|
||||||
|
}
|
||||||
|
}
|
||||||
15
src/translations/fr.json
Normal file
15
src/translations/fr.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"Sort Ascending": "Trier par ordre croissant",
|
||||||
|
"Sort Descending": "Trier par ordre décroissant",
|
||||||
|
"Reset sorting": "Réinitialiser le tri",
|
||||||
|
"Remove column": "Supprimer colonne",
|
||||||
|
"No Data": "Pas de données",
|
||||||
|
"{count} cells copied": {
|
||||||
|
"1": "{count} cellule copiée",
|
||||||
|
"default": "{count} cellules copiées"
|
||||||
|
},
|
||||||
|
"{count} rows selected": {
|
||||||
|
"1": "{count} ligne sélectionnée",
|
||||||
|
"default": "{count} lignes sélectionnées"
|
||||||
|
}
|
||||||
|
}
|
||||||
13
src/translations/index.js
Normal file
13
src/translations/index.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import en from './en.json';
|
||||||
|
import de from './de.json';
|
||||||
|
import fr from './fr.json';
|
||||||
|
import it from './it.json';
|
||||||
|
|
||||||
|
export default function getTranslations() {
|
||||||
|
return {
|
||||||
|
en,
|
||||||
|
de,
|
||||||
|
fr,
|
||||||
|
it,
|
||||||
|
};
|
||||||
|
};
|
||||||
15
src/translations/it.json
Normal file
15
src/translations/it.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"Sort Ascending": "Ordinamento ascendente",
|
||||||
|
"Sort Descending": "Ordinamento decrescente",
|
||||||
|
"Reset sorting": "Azzeramento ordinamento",
|
||||||
|
"Remove column": "Rimuovi colonna",
|
||||||
|
"No Data": "Nessun dato",
|
||||||
|
"{count} cells copied": {
|
||||||
|
"1": "Copiato {count} cella",
|
||||||
|
"default": "{count} celle copiate"
|
||||||
|
},
|
||||||
|
"{count} rows selected": {
|
||||||
|
"1": "{count} linea selezionata",
|
||||||
|
"default": "{count} linee selezionate"
|
||||||
|
}
|
||||||
|
}
|
||||||
11
src/utils.js
11
src/utils.js
@ -138,3 +138,14 @@ export function numberSortAsc(a, b) {
|
|||||||
export function stripHTML(html) {
|
export function stripHTML(html) {
|
||||||
return html.replace(/<[^>]*>/g, '');
|
return html.replace(/<[^>]*>/g, '');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function format(str, args) {
|
||||||
|
if (!str) return str;
|
||||||
|
|
||||||
|
Object.keys(args).forEach(arg => {
|
||||||
|
let regex = new RegExp(`{(${arg})}`, 'g');
|
||||||
|
str = str.replace(regex, args[arg]);
|
||||||
|
});
|
||||||
|
|
||||||
|
return str;
|
||||||
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user