{"action":"created","issue":{"url":"https://api.github.com/repos/ag-grid/ag-grid/issues/2212","repository_url":"https://api.github.com/repos/ag-grid/ag-grid","labels_url":"https://api.github.com/repos/ag-grid/ag-grid/issues/2212/labels{/name}","comments_url":"https://api.github.com/repos/ag-grid/ag-grid/issues/2212/comments","events_url":"https://api.github.com/repos/ag-grid/ag-grid/issues/2212/events","html_url":"https://github.com/ag-grid/ag-grid/issues/2212","id":297472225,"number":2212,"title":"setFilterModel() in async/callback set filter","user":{"login":"Shadrongowes","id":1544805,"avatar_url":"https://avatars2.githubusercontent.com/u/1544805?v=4","gravatar_id":"","url":"https://api.github.com/users/Shadrongowes","html_url":"https://github.com/Shadrongowes","followers_url":"https://api.github.com/users/Shadrongowes/followers","following_url":"https://api.github.com/users/Shadrongowes/following{/other_user}","gists_url":"https://api.github.com/users/Shadrongowes/gists{/gist_id}","starred_url":"https://api.github.com/users/Shadrongowes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Shadrongowes/subscriptions","organizations_url":"https://api.github.com/users/Shadrongowes/orgs","repos_url":"https://api.github.com/users/Shadrongowes/repos","events_url":"https://api.github.com/users/Shadrongowes/events{/privacy}","received_events_url":"https://api.github.com/users/Shadrongowes/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-02-15T14:49:07Z","updated_at":"2018-05-10T17:35:38Z","closed_at":null,"author_association":"NONE","body":"<!--\r\nIF YOU DON'T FILL OUT THE FOLLOWING INFORMATION WE MIGHT CLOSE YOUR ISSUE WITHOUT INVESTIGATING\r\n-->\r\n\r\n**I'm submitting a ...**  (check one with \"x\")\r\n```\r\n[x] bug report => search github for a similar issue or PR before submitting\r\n[ ] feature request\r\n[ ] support request => Please do not submit support request here, instead see https://github.com/ceolter/ag-grid/blob/master/CONTRIBUTING.md#question\r\n```\r\nOriginal fix in AG-1171, reproduction of error in 16.0.0\r\n\r\n**Current behavior**\r\n**setFilterModel()** is unable to filter on a column when async/callback model is used for values, shown [ here ](https://www.ag-grid.com/javascript-grid-filter-set/#example-callback-async).\r\n**setFilterModel()** initiates callback function in **values** attribute, but does not apply filter to column. Once callback is successful, **setFilterModel()** behaves as expected.\r\n\r\n**Expected behavior**\r\nUnopinionated filter applied to column's set filter.\r\n\r\nor \r\n\r\n**setFilterModel()** initiates _values_ callback function, on success filter model is applied.\r\n\r\n**Minimal reproduction of the problem with instructions**\r\n<!--\r\nIf the current behavior is a bug or you can illustrate your feature request better with an example,\r\nplease provide the *STEPS TO REPRODUCE* and if possible a *MINIMAL DEMO* of the problem via\r\nhttps://plnkr.co or similar (you can use this template as a starting point: https://plnkr.co/edit/369YrrgCVrnPjD528OtT).\r\n-->\r\n*STEPS TO REPRODUCE* Method 1\r\n1. Open https://embed.plnkr.co/213Oa6iAZVzMlddfq9CD/\r\n2. Click Apply Filter using setFilterModel() button.\r\n3. Observe (we expect the filter _'value 1'_ to be applied)\r\n4. Wait 5s\r\n5. Click Apply Filter using setFilterModel() button.\r\n6. Observe (function behaves as expected)\r\n\r\n*STEPS TO REPRODUCE* Method 2\r\n1. Open https://embed.plnkr.co/213Oa6iAZVzMlddfq9CD/\r\n2. Select Filter icon on Set filter col column\r\n3. Wait for Set Filter to populate\r\n4. Click Apply Filter using setFilterModel() button.\r\n5. Observe (function behaves as expected)\r\n\r\nOnly applies filter after callback success.\r\n\r\n**What is the motivation / use case for changing the behavior?**\r\n<!-- Describe the motivation or the concrete use case -->\r\nWe leverage ag-grid's asynchronous set filters. These provide significant speed increases and lower transmission payloads for our clients, a very valuable feature. However, we also invoke .setFilterModel in onGridReady to load cached and saved filter configurations. These two features are unable to operate in tandem. \r\n\r\n**Please tell us about your environment:**\r\n<!-- Operating system, IDE, package manager, HTTP server, ... -->\r\nLinux Red Hat 7\r\nSpring Boot 1.3.3\r\nnpm\r\n(Behavior is likely not system dependent)\r\n\r\n* **ag-Grid version:** 16.0.0\r\n\r\n* **Browser:** Google Chrome Version 61.0.3163.100 (Official Build) (32-bit) \r\n\r\n* **Language:** all"},"comment":{"url":"https://api.github.com/repos/ag-grid/ag-grid/issues/comments/388126734","html_url":"https://github.com/ag-grid/ag-grid/issues/2212#issuecomment-388126734","issue_url":"https://api.github.com/repos/ag-grid/ag-grid/issues/2212","id":388126734,"user":{"login":"Bema","id":2582353,"avatar_url":"https://avatars1.githubusercontent.com/u/2582353?v=4","gravatar_id":"","url":"https://api.github.com/users/Bema","html_url":"https://github.com/Bema","followers_url":"https://api.github.com/users/Bema/followers","following_url":"https://api.github.com/users/Bema/following{/other_user}","gists_url":"https://api.github.com/users/Bema/gists{/gist_id}","starred_url":"https://api.github.com/users/Bema/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Bema/subscriptions","organizations_url":"https://api.github.com/users/Bema/orgs","repos_url":"https://api.github.com/users/Bema/repos","events_url":"https://api.github.com/users/Bema/events{/privacy}","received_events_url":"https://api.github.com/users/Bema/received_events","type":"User","site_admin":false},"created_at":"2018-05-10T17:35:38Z","updated_at":"2018-05-10T17:35:38Z","author_association":"NONE","body":"I have the same issue but found a way around it. \r\n\r\nInstead of running `gridOptions.api.setFilterModel(models)`, we have to set each filter model individually using `filterComponent.setModel()`, see below:\r\n\r\n```javascript\r\nforEach(filterModel, (filter, fieldName) => {\r\n    // get filter instance\r\n    const filterComponent = this.gridOptions.api.getFilterInstance(fieldName);\r\n\r\n    filterComponent.setModel({\r\n        type: filter.filterType,\r\n        values: filter.values\r\n    });\r\n\r\n    filterComponent.onFilterChanged();\r\n });\r\n```\r\nOur use case is that we remotely store the grid state (including filter models) so when users reload the application their changes are fully preserved, we extract the filter models using `gridOptions.api.getFilterModel()`, this method returns an object with the following signature:\r\n\r\n```typescript\r\n{\r\n    [fieldName]: {\r\n        filterType: string;\r\n        values: []\r\n    }\r\n}\r\n```\r\n`filterComponent.setModel()` expects an object with property `type` instead of `filterType`, which is a undesired discrepancy. \r\n\r\nUnfortunately I won't have time to figure why  `gridOptions.api.setFilterModel(models)` won't work, I did try to rename `filterType` to `type` but it still won't work. \r\n\r\nAs an enterprise feedback: It would be great to have a single way to subscribe to the grid's state and also a way to easily set its initial state (filters, sorting etc), to be able to do that we had to subscribe to several events and invoke several methods which is unfortunately pretty time consuming and the use case is very common nowadays."}}
{"actor":{"display_login":"Bema"}}