Skip to content

Commit 35ef121

Browse files
committed
make data prop optional; fix: progressiveLoad scroll;
1 parent 7167c41 commit 35ef121

File tree

9 files changed

+90
-61
lines changed

9 files changed

+90
-61
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
## [0.17.0] - 2022-01-18
1+
## [0.17.1] - 2022-01-18
22
- BREAKING: upgraded tabulator-tables to 5.0.10
33
- BREAKING: added "events" prop, callback props (like: rowClick) are now deprecated.
44
- feat: added "checkOptions" prop: if set to true, it will rerender when options changed.
55
- feat: added typescript types: ReactTabulatorOptions
6+
- fix: for pagination using scroll & ajaxURL
67
- use pnpm instead of npm
78

89
## [0.16.1] - 2021-11-15

lib/ConfigUtils.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export interface IProps {
22
events?: any;
33
className?: string;
44
columns: any[];
5-
data: any[];
5+
data?: any[];
66
height?: number;
77
layout?: string;
88
layoutColumnsOnNewData?: boolean;

lib/ConfigUtils.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,20 @@ var propsToOptions = function (props) { return __awaiter(void 0, void 0, void 0,
6868
}
6969
callbackNames = ['tableBuilt', 'rowClick', 'rowDblClick', 'rowContext', 'rowTap', 'rowDblTap', 'rowTapHold',
7070
'rowAdded', 'rowDeleted', 'rowMoved', 'rowUpdated', 'rowSelectionChanged', 'rowSelected', 'rowDeselected', 'rowResized',
71-
'cellClick', 'cellDblClick', 'cellContext', 'cellTap', 'cellDblTap', 'cellTapHold', 'cellEditing', 'cellEdited', 'cellEditCancelled',
71+
'cellClick', 'cellDblClick', 'cellContext', 'cellTap', 'cellDblTap', 'cellTapHold', 'cellEditing', 'cellEditCancelled',
7272
'columnMoved', 'columnResized', 'columnTitleChanged', 'columnVisibilityChanged',
73-
'htmlImporting', 'htmlImported', 'dataLoading', 'dataLoaded', 'dataChanged',
74-
'ajaxRequesting', 'ajaxResponse', 'ajaxError', 'dataFiltering', 'dataFiltered', 'dataSorting', 'dataSorted',
73+
'htmlImporting', 'htmlImported', 'dataLoading', 'dataLoaded',
74+
'ajaxRequesting', 'ajaxResponse', 'dataFiltering', 'dataFiltered', 'dataSorting', 'dataSorted',
7575
'renderStarted', 'renderComplete', 'pageLoaded', 'localized', 'dataGrouping', 'dataGrouped',
7676
'groupVisibilityChanged', 'groupClick', 'groupDblClick', 'groupContext', 'groupTap', 'groupDblTap', 'groupTapHold',
7777
'movableRowsSendingStart', 'movableRowsSent', 'movableRowsSentFailed', 'movableRowsSendingStop', 'movableRowsReceivingStart', 'movableRowsReceived', 'movableRowsReceivedFailed', 'movableRowsReceivingStop',
7878
'validationFailed', 'clipboardCopied', 'clipboardPasted', 'clipboardPasteError',
7979
'downloadReady', 'downloadComplete'];
8080
for (_a = 0, callbackNames_1 = callbackNames; _a < callbackNames_1.length; _a++) {
8181
callbackName = callbackNames_1[_a];
82-
output[callbackName] = props[callbackName] || NOOPS;
82+
if (typeof props[callbackName] !== 'undefined') {
83+
output[callbackName] = props[callbackName] || NOOPS;
84+
}
8385
}
8486
if (!(typeof props['footerElement'] === 'object')) return [3 /*break*/, 2];
8587
return [4 /*yield*/, syncRender(props['footerElement'], document.createElement('div'))];

lib/ReactTabulator.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,11 @@ var default_1 = /** @class */ (function (_super) {
117117
return [4 /*yield*/, (0, ConfigUtils_1.propsToOptions)(this.props)];
118118
case 1:
119119
propOptions = _c.sent();
120-
instance = new tabulator_tables_1.TabulatorFull(domEle, __assign(__assign(__assign(__assign({ columns: columns }, propOptions), { layout: (_a = this.props.layout) !== null && _a !== void 0 ? _a : 'fitColumns',
121-
// tableBuilding() {
122-
// that.table = this; // keep the table instance.
123-
// that.props.tableBuilding ? that.props.tableBuilding() : '';
124-
// },
125-
// dataLoaded() {
126-
// that.props.dataLoaded ? that.props.dataLoaded() : '';
127-
// },
128-
invalidOptionWarnings: false }), options), { // props.options are passed to Tabulator's options.
129-
data: data }));
120+
if (data) {
121+
propOptions.data = data;
122+
}
123+
instance = new tabulator_tables_1.TabulatorFull(domEle, __assign(__assign(__assign({ columns: columns }, propOptions), { layout: (_a = this.props.layout) !== null && _a !== void 0 ? _a : 'fitColumns' }), options // props.options are passed to Tabulator's options.
124+
));
130125
instance.on('tableBuilding', function () {
131126
that.table = this; // keep the table instance.
132127
that.props.tableBuilding ? that.props.tableBuilding() : '';

lib/ReactTabulatorExample.js

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,30 +110,44 @@ var default_1 = /** @class */ (function (_super) {
110110
{ title: 'Email', field: 'email', width: 150 },
111111
];
112112
var options = {
113-
height: 150,
113+
height: 100,
114114
movableRows: true,
115-
ajaxProgressiveLoad: 'scroll',
116-
ajaxProgressiveLoadDelay: 200,
117-
ajaxProgressiveLoadScrollMargin: 100,
115+
progressiveLoad: 'scroll',
116+
progressiveLoadDelay: 200,
117+
progressiveLoadScrollMargin: 30,
118118
ajaxURL: 'https://reqres.in/api/users',
119-
paginationDataSent: {
120-
page: 'page',
121-
size: 'per_page' // change 'size' param to 'per_page'
119+
dataSendParams: {
120+
page: "page",
121+
size: "per_page"
122122
},
123-
paginationDataReceived: {
124-
last_page: 'total_pages'
123+
dataReceiveParams: {
124+
last_page: 'last'
125125
},
126-
current_page: 1,
127-
paginationSize: 3,
126+
paginationSize: 5,
128127
ajaxResponse: function (url, params, response) {
129-
console.log('ajaxResponse', url);
130-
return response; //return the response data to tabulator
128+
console.log('url, params, response', url, params, response);
129+
return {
130+
data: response.data,
131+
last: response.total_pages
132+
};
131133
},
132134
ajaxError: function (error) {
133135
console.log('ajaxError', error);
134136
}
135137
};
136-
return (React.createElement(ReactTabulator_1["default"], { ref: function (ref) { return (_this.ref = ref); }, columns: columns, data: [], options: options }));
138+
return (React.createElement(ReactTabulator_1["default"], { ref: function (ref) { return (_this.ref = ref); }, columns: columns, options: options, events: {
139+
dataLoaded: function (data) {
140+
console.log('dataLoaded', data);
141+
// return data; //return the response data to tabulator
142+
var modResponse = {};
143+
modResponse.data = data;
144+
modResponse.last = 5;
145+
return modResponse;
146+
},
147+
ajaxError: function (error) {
148+
console.log('ajaxError', error);
149+
}
150+
} }));
137151
};
138152
return _this;
139153
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-tabulator",
3-
"version": "0.17.0",
3+
"version": "0.17.1",
44
"description": "React Tabulator is based on tabulator - a JS table library with many advanced features.",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",

src/ConfigUtils.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export interface IProps {
99
events?: any; // example: <ReactTabulator events={{ rowClick: (ev, row) => {} }}... />
1010
className?: string;
1111
columns: any[];
12-
data: any[];
12+
data?: any[];
1313
height?: number;
1414
layout?: string, /// layout type "fitColumns" | "fitDataTable" | "fitDataStretch" | "fitData" - default: "fitData"
1515
layoutColumnsOnNewData?: boolean, // update column widths on setData - default: false
@@ -140,18 +140,20 @@ export const propsToOptions = async (props: any) => {
140140

141141
const callbackNames = ['tableBuilt','rowClick','rowDblClick','rowContext','rowTap','rowDblTap','rowTapHold',
142142
'rowAdded','rowDeleted','rowMoved','rowUpdated','rowSelectionChanged','rowSelected','rowDeselected','rowResized',
143-
'cellClick','cellDblClick','cellContext','cellTap','cellDblTap','cellTapHold','cellEditing','cellEdited','cellEditCancelled',
143+
'cellClick','cellDblClick','cellContext','cellTap','cellDblTap','cellTapHold','cellEditing','cellEditCancelled',
144144
'columnMoved','columnResized','columnTitleChanged','columnVisibilityChanged',
145-
'htmlImporting','htmlImported','dataLoading','dataLoaded','dataChanged',
146-
'ajaxRequesting','ajaxResponse','ajaxError','dataFiltering','dataFiltered','dataSorting','dataSorted',
145+
'htmlImporting','htmlImported','dataLoading','dataLoaded',
146+
'ajaxRequesting','ajaxResponse','dataFiltering','dataFiltered','dataSorting','dataSorted',
147147
'renderStarted','renderComplete','pageLoaded','localized','dataGrouping','dataGrouped',
148148
'groupVisibilityChanged','groupClick','groupDblClick','groupContext','groupTap','groupDblTap','groupTapHold',
149149
'movableRowsSendingStart','movableRowsSent','movableRowsSentFailed','movableRowsSendingStop','movableRowsReceivingStart','movableRowsReceived','movableRowsReceivedFailed','movableRowsReceivingStop',
150150
'validationFailed','clipboardCopied','clipboardPasted','clipboardPasteError',
151151
'downloadReady','downloadComplete']; // don't add "selectableCheck" here, it will break "rowSelectionChanged"
152152

153153
for (const callbackName of callbackNames) {
154-
output[callbackName] = props[callbackName] || NOOPS
154+
if (typeof props[callbackName] !== 'undefined') {
155+
output[callbackName] = props[callbackName] || NOOPS
156+
}
155157
}
156158
if (typeof props['footerElement'] === 'object') {
157159
// convert from JSX to HTML string (tabulator's footerElement accepts string)

src/ReactTabulator.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ export default class extends React.Component<IProps, Partial<IState>> {
3838
const that = this;
3939
const { columns, data, options } = this.props;
4040
const propOptions = await propsToOptions(this.props);
41+
if (data) {
42+
propOptions.data = data;
43+
}
4144

4245
const instance = new Tabulator(domEle, {
4346
columns,
@@ -50,9 +53,7 @@ export default class extends React.Component<IProps, Partial<IState>> {
5053
// dataLoaded() {
5154
// that.props.dataLoaded ? that.props.dataLoaded() : '';
5255
// },
53-
invalidOptionWarnings: false, // #102: disable console warnings for invalid table properties
54-
...options, // props.options are passed to Tabulator's options.
55-
data
56+
...options // props.options are passed to Tabulator's options.
5657
});
5758
instance.on('tableBuilding', function () {
5859
that.table = this; // keep the table instance.

src/ReactTabulatorExample.tsx

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -103,37 +103,51 @@ export default class extends React.Component<IProps> {
103103
{ title: 'Email', field: 'email', width: 150 },
104104
]
105105
const options = {
106-
height: 150,
106+
height: 100,
107107
movableRows: true,
108-
ajaxProgressiveLoad: 'scroll',
109-
ajaxProgressiveLoadDelay: 200,
110-
ajaxProgressiveLoadScrollMargin: 100,
108+
progressiveLoad: 'scroll',
109+
progressiveLoadDelay: 200,
110+
progressiveLoadScrollMargin: 30,
111111
ajaxURL: 'https://reqres.in/api/users',
112-
paginationDataSent: {
113-
page: 'page',
114-
size: 'per_page' // change 'size' param to 'per_page'
112+
dataSendParams:{
113+
page: "page",
114+
size: "per_page",
115115
},
116-
paginationDataReceived: {
117-
last_page: 'total_pages'
116+
dataReceiveParams:{
117+
last_page: 'last'
118118
},
119-
current_page: 1,
120-
paginationSize: 3,
121-
ajaxResponse: function(url: string, params, response) {
122-
console.log('ajaxResponse', url);
123-
return response; //return the response data to tabulator
119+
paginationSize: 5,
120+
ajaxResponse: (url, params, response) => {
121+
console.log('url, params, response', url, params, response);
122+
return {
123+
data: response.data,
124+
last: response.total_pages
125+
};
124126
},
125-
ajaxError: function(error) {
127+
ajaxError: function (error) {
126128
console.log('ajaxError', error);
127129
}
128-
}
130+
};
129131
return (
130132
<ReactTabulator
131-
ref={ref => (this.ref = ref)}
132-
columns={columns}
133-
data={[]}
134-
options={options}
135-
/>
136-
)
133+
ref={(ref) => (this.ref = ref)}
134+
columns={columns}
135+
options={options}
136+
events={{
137+
dataLoaded: function (data) {
138+
console.log('dataLoaded', data);
139+
// return data; //return the response data to tabulator
140+
let modResponse: any = {};
141+
modResponse.data = data;
142+
modResponse.last = 5;
143+
return modResponse;
144+
},
145+
ajaxError: function (error) {
146+
console.log('ajaxError', error);
147+
}
148+
}}
149+
/>
150+
);
137151
}
138152

139153
render() {

0 commit comments

Comments
 (0)