-> will filter store by Approved and Assigned as the same time?
Or will first filter by Approved and after will clear filter and will filter by Assigned?
Also does filterBy actually create a filter inside store?
Please help!!!
PS. Findings:
If you use
this.eventStore.clearFilters();
but this.eventStore.isFiltered = false, then after no matter what filters you apply, they wouldn't work. As a work around, I have to do it like this:
if (this.eventStore.isFiltered) {
this.eventStore.clearFilters();
}
Does nothing at all. You apply filters and after try to add/update events, they stay on the scheduler. The interesting thing, it is somehow creates a copy inside different filters.
If you have an even with field Status. Assume event has status = Submitted.
You apply filter to eventStore with status = Submitted. All good to this point.
Now you change status of event to Approved.
1) Scheduler still shows event even we have applied filter before = Submitted
2) If I filter a store again but with status Submitted, I also see my event. So now a copy of my event exists in store when its filtered by Submitted and also when its filtered by Approved
-> will filter store by Approved and Assigned as the same time?
Or will first filter by Approved and after will clear filter and will filter by Assigned?
The code first filters records by status field equal to 'Approved' then by status field equal to 'Assigned'.
Also does filterBy actually create a filter inside store?
StoreFilter mixin adds filtering to the stores. So store is responsible for filtering. Each filter is an instance of CollectionFilter class. Whenever you call `store.filter()` or `store.filterBy()` it adds a CollectionFilter to the `store.filters`. Adding a filter for the same property will replace the current one, but will not clear any other filters. Adding a filter through the filterBy function is ultimate. It will clear all the property based filters and replace the current filterBy function if present.
To be able to understand what is going on with filters when you change something and to watch for the app state please open Chrome dev tool and add following lines to the "live expression":
// Total filters
scheduler.eventStore.filters.totalCount
// Details
scheduler.eventStore.filters.map(f => `${f.$name} ${f.property} ${f.value} ${f.operator} ${f.filterBy.name}`)
// Total records
scheduler.eventStore.allCount
// Records excluding filtered
scheduler.eventStore.count
2019-02-04_1509.png (238.01 KiB) Viewed 1275 times
If you use
this.eventStore.clearFilters();
but this.eventStore.isFiltered = false, then after no matter what filters you apply, they wouldn't work.
I can't reproduce this. Please open Filtering demo and run in console line by line:
//Check the value
scheduler.eventStore.isFiltered // false
// Clear filters when isFiltered false
scheduler.eventStore.clearFilters()
// Apply filter
scheduler.eventStore.filter('name', 'Make') // Now it's one event on the page
// Clear filters 2 times to make sure this scenario works too
scheduler.eventStore.clearFilters()
scheduler.eventStore.clearFilters()
// Try to filter
scheduler.eventStore.filter('name', 'Make') // One event on the page again
Please provide more details on that, so we can inspect.
Let's try adding first. Please reload the Filtering demo and run in console:
// check value
scheduler.eventStore.reapplyFilterOnAdd // false
// apply filter
scheduler.eventStore.filter('name', 'Make') // only "Make marketing plan" on the screen
// add "Make test" event
scheduler.eventStore.add({"resourceId" : "a", "name" : "Make test", "startDate" : "2017-02-07 11:00", "endDate" : "2017-02-07 14:00"}) // it's on the screen
// add "test" event
scheduler.eventStore.add({"resourceId" : "a", "name" : "test", "startDate" : "2017-02-07 11:00", "endDate" : "2017-02-07 14:00"}) // it's on the screen too, no filter's applied
// remove filters
scheduler.eventStore.clearFilters()
// now change the reapply flag
scheduler.eventStore.reapplyFilterOnAdd = true
// apply filter again
scheduler.eventStore.filter('name', 'Make')
// add ''Make test2"
scheduler.eventStore.add({"resourceId" : "a", "name" : "Make test2", "startDate" : "2017-02-07 11:00", "endDate" : "2017-02-07 14:00"}) // filter's reapplied but it has "Make" in its name so it's on the screen
// add "test2"
scheduler.eventStore.add({"resourceId" : "a", "name" : "test2", "startDate" : "2017-02-07 11:00", "endDate" : "2017-02-07 14:00"}) // test2 is not on the screen. It's been filtered out.
// clear filters
scheduler.eventStore.clearFilters() // test2 is on the screen as well as the others.
Works as expected.
Now let's try updating. Please reload the page and run in console:
// save reference to the "Make marketing plan" event
event = scheduler.eventStore.first
// check the value
scheduler.eventStore.reapplyFilterOnUpdate // false
// apply filter
scheduler.eventStore.filter('name', 'Make')
// rename the event so its name doesn't contain "Make" in it
event.name = 'test' // it's still on the screen
// change the flag
scheduler.eventStore.reapplyFilterOnUpdate = true
// rename the event so its name doesn't contain "Make" in it as well
event.name = 'test2' // no events on the screen. the event's been filtered out.
// rename the event so it has "Make" in its name
event.name = 'Make test2' // the event is visible again
// Clear filters. Same amount of events on the screen
scheduler.eventStore.clearFilters()
Works as expected.
Please provide more details on that too, so we can inspect.
If you have an even with field Status. Assume event has status = Submitted.
You apply filter to eventStore with status = Submitted. All good to this point.
Now you change status of event to Approved.
1) Scheduler still shows event even we have applied filter before = Submitted
2) If I filter a store again but with status Submitted, I also see my event. So now a copy of my event exists in store when its filtered by Submitted and also when its filtered by Approved
I can't reproduce it. Please open the Filtering demo and try in console line by line:
event = scheduler.eventStore.first
event.status = 'Submitted'
scheduler.eventStore.filter('status', 'Submitted') // "All good to this point."
event.status = 'Approved' // "Scheduler still shows event even we have applied filter before = Submitted" because reapplyFilterOnUpdate is false
scheduler.eventStore.filter('status', 'Submitted') // no events shown
scheduler.eventStore.filter('status', 'Approved') // the event is shown
scheduler.eventStore.clearFilters() // Same number of event on the screen. No extra records present.
When I checked your filter issue last Friday I definitely saw some weird behavior. From time to time I got some "ghost" records on the screen. But today I can't reproduce any of the issues I faced with. Probably it was due to switching from branch to branch and some of my local data was not really up-to-date. Sorry for the inconvenience.
I hope this will answer your questions and help to understand how it works. If you face any weird behavior again please let me know and provide some steps to reproduce (similar to my snippets).
PS. For the property based filters you can specify an Id like:
scheduler.eventStore.filter({property : 'name', value : 'Make', id: 'name1'})
scheduler.eventStore.filter({property : 'name', value : 'Make2', id: 'name2'})
Then 2 filters will be applied for the field 'name'. But keep in mind that in the example above they will work as "AND".