A smart Meteor wrapper for the Griddle React component
meteor add utilities:meteor-griddlenpm install --save griddle-react
import { MeteorGriddle } from 'meteor/utilities:meteor-griddle';
The <MeteorGriddle/> React component takes the same options as <Griddle/>, plus a couple extra ones:
publication: the publication that will provide the datacollection: the collection to displaymatchingResultsCount: the name of the matching results counterfilteredFields: an array of fields to search through when filteringsubsManager: An optional meteorhacks:subs-manager instanceexternalFilterDebounceWait: When filtering data loaded from an external source, this time (in milliseconds) will be used to debounce the filter (to prevent results from refreshing on each keystroke). Default time is set to 300 ms. This property will only be used if theuseExternalcomponent property is set totrue. For now the filter debounce option is limited to external data sources only.
<MeteorGriddle
publication="adminUsers"
collection={Meteor.users}
matchingResultsCount="matching-users"
filteredFields={["email", "username", "emails.address", "services.meteor-developer.username"]}
showFilter
/>You'll usually want to pass along some of Griddle's own options, too.
If you're interested in displaying a custom table loading indicator/message, use the Griddle supported externalLoadingComponent property (which accepts a React Component):
<MeteorGriddle
publication="adminUsers"
collection={Meteor.users}
...
externalLoadingComponent={UsersLoading}
/>Note: Griddle uses the externalIsLoading (boolean) property to decide if the loading component should be shown or not. MeteorGriddle takes care of setting this property internally based on the subscription ready state. You do not need to pass this property in (and if you do it will be ignored).
To show and use the Griddle filtering option, you must pass in either a filteredFields or columns property, as well as a showFilter property that's set to true.
<MeteorGriddle
publication="gizmos.all"
collection={gizmos}
matchingResultsCount="gizmos-count"
filteredFields={['name', 'description', 'color']}
showFilter
/>To use any of Griddle's external* properties, you must pass in useExternal (set to true). useExternal is set to false by default.
// Will ignore `externalResultsPerPage`
<MeteorGriddle
publication="gizmos.all"
collection={gizmos}
matchingResultsCount="gizmos-count"
externalResultsPerPage={10}
/>
// Will use `externalResultsPerPage`
<MeteorGriddle
publication="gizmos.all"
collection={gizmos}
matchingResultsCount="gizmos-count"
externalResultsPerPage={10}
useExternal
/> To use Griddle, you need to define a publication in your own codebase. That publication takes two query and options arguments from the client.
Meteor.publish('adminUsers', function (query, options) {
if(Users.isAdminById(this.userId)){
var users = Meteor.users.find(query, options);
// can't reuse "users" cursor
Counts.publish(this, 'matching-users', Meteor.users.find(query, options));
return users;
}
});- The publication should publish a count of matching results using the Publish Counts package.
- Note that an issue with the Publish Counts package prevents you from reusing the same cursor.
- You're trusted to make your own security checks on the
queryandoptionsarguments.
The meteorhacks:subs-manager package can be used with MeteorGriddle to help cache subscriptions. Simply create a new SubsManager instance then pass it in via the subsManager property. For example:
const subsManager = new SubsManager();
const ProductList = () => (
<div className="products">
<MeteorGriddle
publication="products.all"
collection={products}
subsManager={subsManager}
/>
</div>
);- Clarified docs mentioning must have filtered fields or columns defined to use filter.
- Adjusted so
useExternalmust be set to useexternal*properties. Set tofalseby default. - Added
externalFilterDebounceWaitproperty for controlling external data source filter debouncing.