{"action":"created","issue":{"url":"https://api.github.com/repos/primefaces/primefaces/issues/1953","repository_url":"https://api.github.com/repos/primefaces/primefaces","labels_url":"https://api.github.com/repos/primefaces/primefaces/issues/1953/labels{/name}","comments_url":"https://api.github.com/repos/primefaces/primefaces/issues/1953/comments","events_url":"https://api.github.com/repos/primefaces/primefaces/issues/1953/events","html_url":"https://github.com/primefaces/primefaces/issues/1953","id":193822483,"number":1953,"title":"dataTable paginatorAlwaysVisible=\"false\" do not show / hide paginator when filter values change","user":{"login":"mauritz72","id":13729852,"avatar_url":"https://avatars.githubusercontent.com/u/13729852?v=3","gravatar_id":"","url":"https://api.github.com/users/mauritz72","html_url":"https://github.com/mauritz72","followers_url":"https://api.github.com/users/mauritz72/followers","following_url":"https://api.github.com/users/mauritz72/following{/other_user}","gists_url":"https://api.github.com/users/mauritz72/gists{/gist_id}","starred_url":"https://api.github.com/users/mauritz72/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mauritz72/subscriptions","organizations_url":"https://api.github.com/users/mauritz72/orgs","repos_url":"https://api.github.com/users/mauritz72/repos","events_url":"https://api.github.com/users/mauritz72/events{/privacy}","received_events_url":"https://api.github.com/users/mauritz72/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-12-06T16:42:29Z","updated_at":"2016-12-06T18:26:50Z","closed_at":null,"body":"## 1) Environment\r\n- PrimeFaces version: 5.x, 6.0.0 - 6.0.10\r\n- Does it work on the newest PrimeFaces version? no\r\n- Application server + version: JBoss EAP 7.0.3 GA (Mojarra 2.2.12)\r\n- Affected browsers: All major (Firefox, Chrome, Opera, Safari, Edge, IE)\r\n\r\n## 2) Expected behaviour\r\n\r\nWhen using p:dataTable paginatorAlwaysVisible=\"false\" one would expect paginator to display only when needed, also when changing filter values so that if number of visible rows are less than paginator rows, paginator should be hidden, and when filter changes so that number of visible rows exceeds paginator rows, paginator should be shown.\r\n\r\n(Note: If we set paginatorAlwaysVisible=\"true\" (default value), we would expect the paginator to always be present, of course.)\r\n\r\n## 3) Actual behavior\r\n\r\nPaginator does not show or hide dynamically when entering / removing filter values causing number of visible rows increase to above or decrease to below rows count for paginator. Initial display of paginator (at first render of page) works as expected.\r\n\r\n## 4) Steps to reproduce\r\n\r\n1. Run sample below, notice that the paginator is not shown at startup, this is expected, since the initial filter value (\"A\") assumes only one row is displayed, hence paginator should be hidden initially.\r\n2. Remove the filter value (\"A\") from the filter input text box above the first (and only) column. Notice that the paginator is not shown, even though ALL items in the list are actually present in the table now (exceeding rows count). This state is very confusing to user since the user has no idea that there are really more than 5 rows in this table!\r\n3. Refresh the page, notice that the paginator is now made visible (expected).\r\n4. Enter \"B\" in the filter input text box, reducing number of displayed rows to 1. Notice that the paginator is still present, even though visible rows are now less than 5 (expecting it to hide automatically due to paginatorAlwaysVisible=\"false\" setting). \r\n\r\n## 5) Sample XHTML\r\n\r\n```\r\n<h:form id=\"formId\">\r\n\r\n<p:dataTable id=\"tableId\"\r\n    value=\"#{stringListBean.stringListItems}\" var=\"stringListItem\"\r\n    rows=\"5\" paginatorAlwaysVisible=\"false\"\r\n    filterBy=\"#{stringListBean.initialFilterState}\"\r\n    filteredValue=\"#{stringListBean.filteredRows}\">\r\n\r\n    <p:column id=\"stringColId\" headerText=\"Test\"\r\n        filterBy=\"#{stringListItem.string}\"\r\n        filterValue=\"#{stringListBean.filterValue}\"\r\n        filterMatchMode=\"contains\">\r\n       <h:outputText value=\"#{stringListItem.string}\"/>\r\n    </p:column>\r\n\r\n</p:dataTable>\r\n\r\n</h:form>\r\n```\r\n## 6) Sample bean\r\n\r\n```\r\n\r\nimport javax.annotation.PostConstruct;\r\nimport javax.enterprise.context.SessionScoped;\r\nimport javax.inject.Named;\r\nimport java.io.Serializable;\r\nimport java.util.ArrayList;\r\n\r\n@SessionScoped\r\n@Named\r\npublic class StringListBean implements Serializable {\r\n\r\n    private List<StringListItem> stringListItems;\r\n    private List<StringListItem> filteredRows;\r\n    // Initial filter value set to same as first value in list.\r\n    private String filterValue = \"A\";\r\n\r\n    @PostConstruct\r\n    private void init() {\r\n        stringListItems = new ArrayList<>();\r\n        stringListItems.add(new StringListItem(\"A\"));\r\n        stringListItems.add(new StringListItem(\"B\"));\r\n        stringListItems.add(new StringListItem(\"C\"));\r\n        stringListItems.add(new StringListItem(\"D\"));\r\n        stringListItems.add(new StringListItem(\"E\"));\r\n        stringListItems.add(new StringListItem(\"F\"));\r\n        stringListItems.add(new StringListItem(\"G\"));\r\n        stringListItems.add(new StringListItem(\"H\"));\r\n    }\r\n\r\n    public List<FilterState> getInitialFilterState() {\r\n        List<FilterState> initialFilterState = new ArrayList<>();\r\n        // Send current filter value as initial filter value\r\n        initialFilterState.add(new FilterState(\"formId:tableId:stringColId\", filterValue);\r\n        return initialFilterState;\r\n    }\r\n\r\n    public List<StringListItem> getStringListItems() {\r\n        return stringList;\r\n    }\r\n\r\n    public List<StringListItem> getFilteredRows() {\r\n        return this.filteredRows;\r\n    }\r\n\r\n    public void setFilteredRows(List<StringListItem> filteredRows) {\r\n        this.filteredRows = filteredRows;\r\n    }\r\n\r\n    public String getFilterValue() {\r\n        return filterValue;\r\n    }\r\n\r\n    public void setFilterValue(String filterValue) {\r\n        this.filterValue = filterValue;\r\n    }\r\n}\r\n\r\npublic class StringListItem implements Serializable {\r\n    private String string;\r\n\r\n    public StringListItem() { }\r\n\r\n    public StringListItem(String string) {\r\n        this.string = string;\r\n    }\r\n\r\n    public String getString() {\r\n        return string;\r\n    }\r\n\r\n    public void setString(String string) {\r\n        this.string = string;\r\n    }\r\n}\r\n\r\n```\r\n\r\n\r\n## 7) Workaround\r\n\r\nWe have created a workaround for this issue (so that the paginator is hidden when visible row count goes below configured rows per page count) by a using a PostFilterEvent listener (f:event type=\"org.primefaces.event.data.PostFilterEvent\" listener=\"...\") that calls a custom JavaScript by adding a class having CSS display: none; every time filter values are changed by user.\r\n\r\n(we could not use the regular p:ajax event=\"filter\" listener, since filteredRows are not set until just before the PostFilterEvent is called, and we need the filteredRows.size() to determine if visible rows are less than rows configured for paginator.)\r\n\r\nThe JavaScript simply adds CSS 'display: none;' to the ui-paginator div to hide it. This, of course requires that the paginator is rendered at all times, so we need to have both paginator=\"true\" and paginatorAlwaysVisible=\"true\" to make sure it is rendered otherwise we cannot make it visible when filters are removed after initially not shown and visible rows exceeds paginator rows :-D.\r\n\r\nIt would of course be nice if the paginatorAlwaysVisible=\"false\" handled all this automagically so we did not have to have custom event handling and JS everywhere we use p:dataTable."},"comment":{"url":"https://api.github.com/repos/primefaces/primefaces/issues/comments/265230558","html_url":"https://github.com/primefaces/primefaces/issues/1953#issuecomment-265230558","issue_url":"https://api.github.com/repos/primefaces/primefaces/issues/1953","id":265230558,"user":{"login":"jxmai","id":10467831,"avatar_url":"https://avatars.githubusercontent.com/u/10467831?v=3","gravatar_id":"","url":"https://api.github.com/users/jxmai","html_url":"https://github.com/jxmai","followers_url":"https://api.github.com/users/jxmai/followers","following_url":"https://api.github.com/users/jxmai/following{/other_user}","gists_url":"https://api.github.com/users/jxmai/gists{/gist_id}","starred_url":"https://api.github.com/users/jxmai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jxmai/subscriptions","organizations_url":"https://api.github.com/users/jxmai/orgs","repos_url":"https://api.github.com/users/jxmai/repos","events_url":"https://api.github.com/users/jxmai/events{/privacy}","received_events_url":"https://api.github.com/users/jxmai/received_events","type":"User","site_admin":false},"created_at":"2016-12-06T18:26:50Z","updated_at":"2016-12-06T18:26:50Z","body":"Duplicate of #1715 (The same bug), which has already been marked as defect."}}
{"actor":{"display_login":"jxmai"}}