From 551e457637b6ddd42cf21ac1eca84234ede4f63a Mon Sep 17 00:00:00 2001 From: Jovanni Hernandez Date: Tue, 18 Dec 2018 20:33:12 +0000 Subject: [PATCH] Resolves #7 by adding list of supported properties at the parent component that can be passed down to react-table --- public/routes_menu_config.json | 2 ++ .../Widgets/TabularDataFromAPIWidget.js | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/public/routes_menu_config.json b/public/routes_menu_config.json index 984ba6c..ccd9673 100644 --- a/public/routes_menu_config.json +++ b/public/routes_menu_config.json @@ -82,6 +82,8 @@ { "name" : "TabularDataFromAPIWidget", "props" : { + "pageSizeOptions": [50, 100, 250, 500, 1000], + "defaultPageSize": 500, "endpoint" : "/sample_nested_table_data_api.json", "api_response_data_key" : "users", "sub_component" : { diff --git a/src/Dashboard/Widgets/TabularDataFromAPIWidget.js b/src/Dashboard/Widgets/TabularDataFromAPIWidget.js index 74cf1ab..354a1c9 100644 --- a/src/Dashboard/Widgets/TabularDataFromAPIWidget.js +++ b/src/Dashboard/Widgets/TabularDataFromAPIWidget.js @@ -7,6 +7,7 @@ import qs from 'qs'; import { INTERWIDGET_MESSAGE_TYPES } from '../../redux/actions/Dashboard.js'; import { ArrayTabularDataAccessor, BulletedListFormatter, AdditionalDataSubComponent, SubmitAndAdditionalDataSubComponent, UniqueValuesSelectFilter, ArrayValuesSelectFilter } from '../../Helpers/ReactTableHelpers.js' import { stripQueryStringSeperator } from '../../Helpers/Generic.js' +import pick from 'lodash/pick'; // Data Table Imports import ReactTable from "react-table"; @@ -32,6 +33,14 @@ class TabularDataFromAPIWidget extends Component { data:[] }) + // Enumerates the react-table properties that can be set via props + this.supportedReactTableProps = [ + "showPageSizeOptions", + "pageSizeOptions", + "defaultPageSize", + "minRows" + ] + } @@ -448,11 +457,12 @@ class TabularDataFromAPIWidget extends Component { default : { break; } - } - } - + + // Fetch the supported react-table properties from the parent component + let reactTableProps = pick(this.props, this.supportedReactTableProps) + return ( @@ -482,7 +492,7 @@ class TabularDataFromAPIWidget extends Component { defaultFiltered={this.defaultFilters} defaultSorted={this.defaultSorts} - + {...reactTableProps} {...additionalProps} />