reactive-table icon indicating copy to clipboard operation
reactive-table copied to clipboard

Cannot filter function results

Open ghost opened this issue 9 years ago • 2 comments

Using either the standard filter or custom filters I cannot filter function results The right column shows whether the left column has > 0 tickets remaining. 'Sold Out' appears when there are 0 remaining. However I cannot filter by 'Sold Out' or 'Available'. It seems that reactive-table only filters collections. No matter what. Am I missing something?

{fieldId: 'remaining', key: 'date', label: 'Tickets Avail.', fn: function(value, object) {
    var eventDates = CalEvent.findOne({ group: groupId, end: value}) && CalEvent.findOne({ group: groupId, end: value}).end;
    var countEvents = CalEvent.find({ group: groupId, end: value}) && CalEvent.find({ group: groupId, end: value}).count();
    var groupMax = Groups.findOne({ _id: groupId}) && Groups.findOne({ _id: groupId}).maxTickets;
    if(value == eventDates) {
        return groupMax - countEvents
    } else {
        return groupMax
    }
}},
{fieldId: 'left', key: 'date', label: 'Reserve', fn: function(value, object) {
    var eventDates = CalEvent.findOne({ group: groupId, end: value}) && CalEvent.findOne({ group: groupId, end: value}).end;
    var countEvents = CalEvent.find({ group: groupId, end: value}) && CalEvent.find({ group: groupId, end: value}).count();
    var groupMax = Groups.findOne({ _id: groupId}) && Groups.findOne({ _id: groupId}).maxTickets;
    if (((groupMax - countEvents) > 0) || !eventDates) {
                return 'Available'
    } else {
        return 'Sold Out'
    }
}}

ghost avatar Dec 29 '15 16:12 ghost

I was able to achieve a solution by creating a loop to create additional filters, but using a loop to create 81 individual filters is definitely not a clean solution lol. Any input?

ghost avatar Dec 29 '15 22:12 ghost

Yeah, the reactive table filters only work with the collection itself. If you denormalized your data so that there was a field with the number of tickets left, you could filter on that, but otherwise I can't think of anything better than creating individual filters.

aslagle avatar Jan 03 '16 01:01 aslagle