You should still be able to get this all working with ReactiveVar
's. I like using Griddle in Meteor+React apps, so here are a few quick code snippets from a recent project - hope this helps!
TransactionsContainer.js
import { Meteor } from 'meteor/meteor';
import { withTracker } from 'meteor/react-meteor-data';
import { ReactiveVar } from 'meteor/reactive-var';
import { carbonOffsetTransactionsCollection } from 'meteor/l2:common';
import { TransactionsTable } from './TransactionsTable';
import { getTransactionsCount } from '../../../api/carbon-offsets/methods';
const tableConfig = new ReactiveVar({
pageProperties: {
currentPage: 1,
pageSize: 10,
recordCount: 0,
},
sortProperties: [
{ id: 'timestamp', sortAscending: false },
],
filter: null,
});
export const TransactionsContainer = withTracker(() => {
const config = tableConfig.get();
getTransactionsCount.call((error, count) => {
if (config.pageProperties.recordCount !== count) {
config.pageProperties.recordCount = count;
tableConfig.set(config);
}
});
const sort = {
[config.sortProperties[0].id]:
config.sortProperties[0].sortAscending ? 1 : -1,
};
const transactionsHandle = Meteor.subscribe('carbonOffsetTransactions', {
filter: config.filter,
limit: config.pageProperties.pageSize,
skip: config.pageProperties.currentPage < 0
? 0
: (config.pageProperties.currentPage - 1) * config.pageProperties.pageSize,
sort,
});
return {
transactionsReady: transactionsHandle.ready(),
transactions: carbonOffsetTransactionsCollection.find({}, { sort }).fetch(),
tableConfig,
};
})(TransactionsTable);
TransactionsTable.js
import React from 'react';
import PropTypes from 'prop-types';
import Griddle, { RowDefinition, ColumnDefinition } from 'griddle-react';
import { TablePagination } from '../table/TablePagination';
import { NextButton } from '../table/NextButton';
import { PreviousButton } from '../table/PreviousButton';
import { Filter } from '../table/Filter';
import { DateCell } from '../table/DateCell';
export const TransactionsTable = ({ transactions, tableConfig }) => {
const config = tableConfig.get();
return (
<Griddle
data={transactions}
styleConfig={{
classNames: {
Table: 'table',
},
}}
components={{
Filter,
Pagination: TablePagination,
NextButton,
PreviousButton,
}}
pageProperties={{ ...config.pageProperties }}
sortProperties={[...config.sortProperties]}
enableSettings={false}
events={{
onPrevious() {
config.pageProperties.currentPage -= 1;
tableConfig.set(config);
},
onNext() {
config.pageProperties.currentPage += 1;
tableConfig.set(config);
},
onGetPage(pageNumber) {
config.pageProperties.currentPage = pageNumber;
tableConfig.set(config);
},
onSort({ id }) {
if (config.sortProperties[0].id === id) {
config.sortProperties[0].sortAscending =
!config.sortProperties[0].sortAscending;
} else {
config.sortProperties[0] = {
id,
sortAscending: true,
};
}
config.pageProperties.currentPage = 1;
tableConfig.set(config);
},
onFilter(filterText) {
config.filter = filterText;
config.pageProperties.currentPage = 1;
tableConfig.set(config);
},
}}
>
<RowDefinition>
<ColumnDefinition
id="timestamp"
title="Timestamp"
type="date"
customComponent={DateCell}
/>
<ColumnDefinition id="transactionType" title="Type" />
<ColumnDefinition id="carbonOffsetAmount" title="Purchse Amount ($)" />
<ColumnDefinition id="partnerId" title="Partner ID" />
<ColumnDefinition id="customerEmailHash" title="Customer Email Hash" />
</RowDefinition>
</Griddle>
);
};
TransactionsTable.propTypes = {
transactions: PropTypes.array,
tableConfig: PropTypes.object.isRequired,
};
TransactionsTable.defaultProps = {
transactions: [],
};