There are three issues that I am looking at which are intertwined and related to multivalue lookup.
1. With pagination on the lookup results, only selections from the visible page are returned
2. When server side paging is enabled, selection from the non visible pages are not retained as you move through the pages.
3. With server side paging and non dataTable rendering "Return Selected" button does not get enabled when clicking on a checkbox.
I have setup examples to enable server side paging both with and without dataTable by providing a custom viewName to the quickFinder. I have attached the XML for reference.
For item 2. Server side paging with or without dataTable causes only one page worth of content to be present in the DOM. Selection made client side are not being saved anywhere to be accessed later as the user pages through the results.
For item 3. onChange event listener is written only for dataTable based rendering of results.
I can think of two solutions
1. Use a client side JSON object to store the user selections. The JSON object won't be replaced as part of component refresh in case of server side paging. We can then use the JSON object to calculate if 'Return Selected' button should be enabled and also to populate hidden variables on submit. In this approach, once a page is retrieved from the server, we would have to reset any selections that were present on the page from the JSON object. This solution will work for both serverPaging and default paging provided by dataTable.
2. In the other solution, for every select/deselect event a call will be made to a controller method that will record the event server side. This will fix the issue of preserving selections as the user moves through different pages. To solve the problem of retaining the right state for "Return Selected" button we would need to use a counter logic instead of boolean that is there right now. With every selection we increment the counter and with every deselection we decrement the counter. If the counter is at 0, we disable the button else the button stays enabled. This way even if the user moves to a new page the button would know what state it is in. In this solution on submit, instead of reading the selections from request, the collection stored on the server needs to be read to identify which line items need to be processed.
Also for solution 2, the JS function 'handleCheckboxLabelClick' needs to be updated so that it sends a request to the server if server paging is enabled.
Solution 1, has lower performance impact as it would not require a server call for every select/deselect. It is also a single solution that can be applied to all use cases (client side dataTable only, with server paging and dataTable and with server paging without dataTable)