Skip to content

Commit

Permalink
Add typing for .getPlugin statements
Browse files Browse the repository at this point in the history
  • Loading branch information
sequba committed May 14, 2024
1 parent 5e6fd70 commit a037c86
Show file tree
Hide file tree
Showing 14 changed files with 30 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Handsontable from 'handsontable';
import 'handsontable/dist/handsontable.full.min.css';
import {ExportFile} from 'handsontable/plugins'

const container = document.querySelector('#example2');
const button = document.querySelector('#export-blob');
Expand All @@ -23,7 +24,7 @@ const hot: Handsontable = new Handsontable(container, {
licenseKey: 'non-commercial-and-evaluation'
});

const exportPlugin = hot.getPlugin('exportFile');
const exportPlugin: ExportFile = hot.getPlugin('exportFile');

button.addEventListener('click', () => {
const exportedBlob = exportPlugin.exportAsBlob('csv', {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Handsontable from 'handsontable';
import 'handsontable/dist/handsontable.full.min.css';
import {ExportFile} from 'handsontable/plugins'

const container = document.querySelector('#example3');
const button = document.querySelector('#export-string');
Expand All @@ -23,7 +24,7 @@ const hot: Handsontable = new Handsontable(container, {
licenseKey: 'non-commercial-and-evaluation'
});

const exportPlugin = hot.getPlugin('exportFile');
const exportPlugin: ExportFile = hot.getPlugin('exportFile');

button.addEventListener('click', () => {
const exportedString = exportPlugin.exportAsString('csv', {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Handsontable from 'handsontable';
import 'handsontable/dist/handsontable.full.min.css';
import {Filters} from 'handsontable/plugins'

const container = document.querySelector('#exampleExcludeRowsFromFiltering');
const handsontableInstance: Handsontable = new Handsontable(container, {
Expand Down Expand Up @@ -172,7 +173,8 @@ const handsontableInstance: Handsontable = new Handsontable(container, {
// enable the column menu
dropdownMenu: true,
afterFilter() {
const filtersRowsMap = this.getPlugin('filters').filtersRowsMap;
const filtersPlugin: Filters = (this as Handsontable).getPlugin('filters');
const filtersRowsMap = filtersPlugin.filtersRowsMap;

filtersRowsMap.setValueAtIndex(0, false);
filtersRowsMap.setValueAtIndex(filtersRowsMap.indexedValues.length - 1, false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Handsontable from 'handsontable';
import 'handsontable/dist/handsontable.full.min.css';
import {Filters} from 'handsontable/plugins'

const container = document.querySelector('#exampleFilterOnInitialization');
const handsontableInstance: Handsontable = new Handsontable(container, {
Expand Down Expand Up @@ -96,7 +97,7 @@ const handsontableInstance: Handsontable = new Handsontable(container, {
afterInit() {
const handsontableInstance = this;
// get the `Filters` plugin, so you can use its API
const filters = handsontableInstance.getPlugin('Filters');
const filters: Filters = handsontableInstance.getPlugin('filters');

// filter data by the 'Price' column (column at index 2)
// to display only items that are less than ('lt') $200
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Handsontable from 'handsontable';
import 'handsontable/dist/handsontable.full.min.css';
import {Filters} from 'handsontable/plugins'

const container = document.querySelector('#exampleFilterThroughAPI1');
const handsontableInstance: Handsontable = new Handsontable(container, {
Expand Down Expand Up @@ -99,7 +100,7 @@ const handsontableInstance: Handsontable = new Handsontable(container, {
});

// get the `Filters` plugin, so you can use its API
const filters = handsontableInstance.getPlugin('Filters');
const filters: Filters = handsontableInstance.getPlugin('filters');

document.querySelector('.filterBelow200').addEventListener('click', () => {
// clear any existing filters
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Handsontable from 'handsontable';
import 'handsontable/dist/handsontable.full.min.css';
import {Filters} from 'handsontable/plugins'

const container = document.querySelector('#exampleQuickFilter');
const filterField = document.querySelector('#filterField');
Expand Down Expand Up @@ -98,7 +99,7 @@ const handsontableInstance: Handsontable = new Handsontable(container, {

// add a filter input listener
filterField.addEventListener('keyup', (event) => {
const filters = handsontableInstance.getPlugin('filters');
const filters: Filters = handsontableInstance.getPlugin('filters');
const columnSelector = document.getElementById('columns');
const columnValue = columnSelector.value;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Handsontable from 'handsontable';
import 'handsontable/dist/handsontable.full.min.css';
import {NestedRows} from 'handsontable/plugins'

const container = document.querySelector('#example8');
const hot: Handsontable = new Handsontable(container, {
Expand Down Expand Up @@ -29,15 +30,15 @@ const hot: Handsontable = new Handsontable(container, {
colHeaders: ['sum', 'min', 'max', 'count', 'average'],
columnSummary() {
const endpoints = [];
const nestedRowsPlugin = this.hot.getPlugin('nestedRows');
const nestedRowsPlugin: NestedRows = this.hot.getPlugin('nestedRows');
const getRowIndex = nestedRowsPlugin.dataManager.getRowIndex.bind(nestedRowsPlugin.dataManager);
const resultColumn = 0;

let tempEndpoint = null;
let nestedRowsCache = null;

if (nestedRowsPlugin.isEnabled()) {
nestedRowsCache = this.hot.getPlugin('nestedRows').dataManager.cache;
nestedRowsCache = nestedRowsPlugin.dataManager.cache;
} else {
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Handsontable from 'handsontable';
import { HyperFormula } from 'hyperformula';
import 'handsontable/dist/handsontable.full.min.css';
import {Formulas} from 'handsontable/plugins'

const data: (string | number)[][] = [
['Travel ID', 'Destination', 'Base price', 'Price with extra cost'],
Expand Down Expand Up @@ -30,7 +31,7 @@ const hotNamedExpressions: Handsontable = new Handsontable(container, {
});

const input = document.getElementById('named-expressions-input');
const formulasPlugin = hotNamedExpressions.getPlugin('formulas');
const formulasPlugin: Formulas = hotNamedExpressions.getPlugin('formulas');
const button = document.getElementById('named-expressions-button');

button.addEventListener('click', (event) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Handsontable from 'handsontable';
import 'handsontable/dist/handsontable.full.min.css';
import {Search} from 'handsontable/plugins'

const container = document.querySelector('#example1');
const searchField = document.querySelector('#search_field');
Expand All @@ -24,7 +25,7 @@ const hot: Handsontable = new Handsontable(container, {
// add a search input listener
searchField.addEventListener('keyup', (event) => {
// get the `Search` plugin's instance
const search = hot.getPlugin('search');
const search: Search = hot.getPlugin('search');
// use the `Search` plugin's `query()` method
const queryResult = search.query(event.target.value);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Handsontable from 'handsontable';
import 'handsontable/dist/handsontable.full.min.css';
import {Search} from 'handsontable/plugins'

const container = document.querySelector('#example2');
const searchField = document.querySelector('#search_field2');
Expand All @@ -25,7 +26,7 @@ const hot: Handsontable = new Handsontable(container, {
});

searchField.addEventListener('keyup', (event) => {
const search = hot.getPlugin('search');
const search: Search = hot.getPlugin('search');
const queryResult = search.query(event.target.value);

console.log(queryResult);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Handsontable from 'handsontable';
import 'handsontable/dist/handsontable.full.min.css';
import {Search} from 'handsontable/plugins'

const container = document.querySelector('#example3');
const searchField = document.querySelector('#search_field3');
Expand Down Expand Up @@ -30,7 +31,7 @@ const hot: Handsontable = new Handsontable(container, {
});

searchField.addEventListener('keyup', (event) => {
const search = hot.getPlugin('search');
const search: Search = hot.getPlugin('search');
// use the `Search`'s `query()` method
const queryResult = search.query(event.target.value);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Handsontable from 'handsontable';
import 'handsontable/dist/handsontable.full.min.css';
import {Search} from 'handsontable/plugins'

const container = document.querySelector('#example4');
const searchField = document.querySelector('#search_field4');
Expand Down Expand Up @@ -44,7 +45,7 @@ const hot: Handsontable = new Handsontable(container, {
searchField.addEventListener('keyup', (event) => {
searchResultCount = 0;

const search = hot.getPlugin('search');
const search: Search = hot.getPlugin('search');
const queryResult = search.query(event.target.value);

console.log(queryResult);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Handsontable from 'handsontable';
import 'handsontable/dist/handsontable.full.min.css';
import {ColumnSorting} from 'handsontable/plugins'

const container = document.querySelector('#exampleSortByAPI');
const buttonSortAscending = document.querySelector('#sort_asc');
Expand Down Expand Up @@ -98,7 +99,7 @@ const handsontableInstance: Handsontable = new Handsontable(container, {
licenseKey: 'non-commercial-and-evaluation',
});

const columnSorting = handsontableInstance.getPlugin('columnSorting');
const columnSorting: ColumnSorting = handsontableInstance.getPlugin('columnSorting');

buttonSortAscending.addEventListener('click', () => {
columnSorting.sort({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Handsontable from 'handsontable';
import 'handsontable/dist/handsontable.full.min.css';
import {MultiColumnSorting} from 'handsontable/plugins'

const container = document.querySelector('#exampleSortByAPIMultipleColumns');
const buttonSort = document.querySelector('#sort');
Expand Down Expand Up @@ -97,7 +98,7 @@ const handsontableInstance: Handsontable = new Handsontable(container, {
licenseKey: 'non-commercial-and-evaluation',
});

const multiColumnSorting = handsontableInstance.getPlugin('multiColumnSorting');
const multiColumnSorting: MultiColumnSorting = handsontableInstance.getPlugin('multiColumnSorting');

buttonSort.addEventListener('click', () => {
multiColumnSorting.sort([
Expand Down

0 comments on commit a037c86

Please sign in to comment.