Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataTable: MultiViewState with a LazyDataModel #2155

Closed
benoitbb opened this issue Mar 8, 2017 · 9 comments
Closed

DataTable: MultiViewState with a LazyDataModel #2155

benoitbb opened this issue Mar 8, 2017 · 9 comments
Labels
🐞 defect Bug...Something isn't working Resolution: Invalid Issue or pull request is not valid in the latest version

Comments

@benoitbb
Copy link

benoitbb commented Mar 8, 2017

1) Environment

  • PrimeFaces version: 6.1.RC1
  • Application server + version: jboss eap 6.4
  • Affected browsers: Not related to a specific browser I think

I do not understand what's happen in my code. I have to add piece of javascript code after the datatable to force the submit of the filter values. So when I access to a page I first load datas without filtering and then I have to load data again with filtering. I can see the filter values but they are not submitted at the first load of the page.

2) Expected behavior

Same behaviour than the showcase (http://www.primefaces.org/showcase/ui/data/datatable/tableState.xhtml) but with a LazyDataModel List

3) Actual behavior

I have to add a piece of javascript after the datatable declaration to make the filters appear in the "load" function.
<script type="text/javascript"> $(document).ready(function () { PF('processes').filter() }); </script>
..

4) Steps to reproduce

  • Create a LazyDatamodel List and a datatable component,
  • Override the "load" method (public List load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters).
  • add a filter on a column
  • enter a filter value, and check the filter is applied
  • then go on another page
  • and come back
  • The filter value in the input filter is still there but this value never come in the load overrided function

5) Sample XHTML

<p:dataTable id="processes" widgetVar="processes" var="proc" value="#{processDTODataModel}" filteredValue="#{processesController.filteredProcessesDto}" selection="#{processesController.selectedItems}" rows="#{processDTODataModel.nbRows}" first="#{processDTODataModel.firstIndex}" paginatorTemplate="#{processDTODataModel.paginatorTemplate}" currentPageReportTemplate="#{processDTODataModel.currentPageReportTemplate}" rowsPerPageTemplate="#{processDTODataModel.rowsPerPageTemplate}" multiViewState="true" selectionMode="multiple" rowKey="#{proc.id}" paginatorPosition="top" disabledTextSelection="false" reflow="true" paginator="true" lazy="true">
..

6) Sample bean

`@Named
@ViewAccessScoped
public class ProcessInstanceCommentDTODateModel extends LazyDataModelWrapper {

@Inject
private IPaginationService paginationService;

private ProcessInstanceCommentSearch criterias;

public void init(ProcessInstanceCommentSearch criterias) {
    this.criterias = criterias;
}

@Override
public List<ProcessInstanceCommentDTO> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) {

    try {

        ....

        setRowCount(paginationService.countProcessInstanceCommentDTO(criterias));
        wrappedDatas = paginationService.paginateProcessInstanceCommentDTO(criterias);

    } catch (Throwable e) {
        .....
    }
    return wrappedDatas;
}

@Override
public Object getRowKey(ProcessInstanceCommentDTO value) {
    return value.getId();
}

@Override
public ProcessInstanceCommentDTO getRowData(String s) {
	...
}

}`
..
Could you have a look please ?

Thank you.

Regards,

@jamesdcampbell
Copy link

I'm having the same issue. When going back to the page, none of the filters are being sent to the LazyDataModel.

@benoitbb
Copy link
Author

benoitbb commented Apr 18, 2017

Hello guys,

Any chance to have an answer for this issue ?

Thank you.
Regards,

@jamesdcampbell
Copy link

I just used two listeners to save the state of the pagination and filters till they get it working with the LazyDataModel. So it would look like:

XHTML:

<p:dataTable first="#{dataTableController.first} filters="#{dataTableController.filters}" ........>
      <p:ajax event="page" listener="#{dataTableController.onPageChange}"/>  
      <p:ajax event="filter" listener="#{dataTableController.filterListener}"/>

       //DatatableStuff

</p:dataTable>


Controller

   ///Create an int and a Map for "First" and "Filters" along with get/set

    public void onPageChange(PageEvent event) {
    	this.setFirst(((DataTable) event.getSource()).getFirst());
    }

    public void filterListener(FilterEvent filterEvent) {
    	this.setFilters(((DataTable) filterEvent.getSource()).getFilters());
    }

This seems to give the datatable the intended functionality and is a good bandaid for now.

@benoitbb
Copy link
Author

benoitbb commented Apr 19, 2017

Hello,
Yes this should do the job. But to be in the same scope as the option MultiViewState (Session scope), the int and the Map has to be in a session Bean scope. ( I do not know if your "controller" dataTableController is a scope Session Bean )

Regards,

@yeraym
Copy link

yeraym commented Jun 21, 2017

I was having the same issue setting MultiViewState in DataTable with LazyLoad using 6.1.

I was trying to solve it in the backing bean by binding the table to a UIComponent (my idea was to save the TableState manually) when I noticed that after binding the table the problem disapeared.

So, if you just set the binding attribute of the LazyLoad DataTable to a UIComponent in the backing bean the MultiViewState atribute works without doing anything else.

EDIT: my solution has other side effects but jamesdcampbell's works for me so that's what I'm using.

@uvoigt
Copy link

uvoigt commented Sep 27, 2017

It looks like in org.primefaces.component.datatable.DataTable.restoreTableState() the filters are set using datatable's setFilterBy whereas in loadLazyData getFilters is used to call lazyModel.load

@RicoApfelbeck
Copy link

we have the same filter problem with lazyModels, the filter text in the header will be restored but the data where not filtered, sorting and paging is working correctly

@cnsgithub
Copy link
Contributor

@benoitbb If you like this to get fixed, you should provide a reproducer or at least a minimal but complete peace of code that can just be taken and tried out with copy and paste...

@tandraschko tandraschko changed the title MultiViewState with a LazyDataModel Datatable DataTable: MultiViewState with a LazyDataModel Aug 30, 2018
@tandraschko
Copy link
Member

Feel free to reopen - or create a new issue but with runnable example (at best a forked primefaces-test project)

@tandraschko tandraschko added Resolution: Invalid Issue or pull request is not valid in the latest version 🐞 defect Bug...Something isn't working labels Aug 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 defect Bug...Something isn't working Resolution: Invalid Issue or pull request is not valid in the latest version
Projects
None yet
Development

No branches or pull requests

7 participants