Skip to content

Commit

Permalink
Merge pull request #119 from AdamBrodzinski/change-selector-opt
Browse files Browse the repository at this point in the history
adds changeSelector method
  • Loading branch information
aldeed committed Apr 23, 2015
2 parents e228327 + e58a3a5 commit 814a86b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,22 @@ TabularTables.People = new Tabular.Table({
});
```


## Modifying the selector

If your table requires the selector to be modified before it's published, you can modify it with the `changeSelector` method. This can be useful for modifying what will be returned in a search.

```js
TabularTables.Posts = new Tabular.Table({
// other properties...
changeSelector: function(selector) {
// modify it here ...
return selector;
}
});
```


## Security

You can optionally provide an `allow` and/or `allowFields` function to control which clients can get the published data. These are used by the built-in publications on the server only.
Expand Down
1 change: 1 addition & 0 deletions common.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Tabular.Table = function (options) {
self.onUnload = options.onUnload;
self.allow = options.allow;
self.allowFields = options.allowFields;
self.changeSelector = options.changeSelector;

if (_.isArray(options.extraFields)) {
var fields = {};
Expand Down
5 changes: 5 additions & 0 deletions server/tabular.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ Meteor.publish("tabular_getInfo", function(tableName, selector, sort, skip, limi

selector = selector || {};

// Allow the user to modify the selector before we use it
if (typeof table.changeSelector === 'function') {
selector = table.changeSelector(selector);
}

// Apply the server side selector specified in the tabular
// table constructor. Both must be met, so we join
// them using $and, allowing both selectors to have
Expand Down

0 comments on commit 814a86b

Please sign in to comment.