How to keep selection when paging thru a view?

£可爱£侵袭症+ 提交于 2019-12-10 23:15:30

问题


I have a simple view ( first column shows checkbox ) with a pager on top. I would like to make a selection of documents that then will be exported to Excel ( using apache POI ).

I can select 2 documents on page 1, but when I switch to another page to select more documents, all my selection on page 1 is gone.

How can I keep selection when paging thru the view??


回答1:


Retrieving a list of selected ids can be done with

viewPanel.getSelectedIds()

but I assume, because of your question, this is for the current page only. A solution would be to add a custom checkbox column with a serverside onclick event which will add the current selected notedid into a scoped var (containing a vector). On load of the row you will check if this var is found and if so check the checkbox. When you switch between pages you can select more documents.

When you are done selecting, you can use the generated vector to generate the excel document. After generation is done clean the scoped var again and you are done.

Easy as pie ;)




回答2:


Have you tried the pagerSaveState in the Extension Library?

Not sure how much of the state information it stores.




回答3:


Ulrich,

It would be a bit brute force; but I may have a suggestion. I don't have time to implement it, but I'll try to explain how it works.

We have two problems here. we have to save selected items on one page and restore them if you return to the same page again.

Usual checkbox in view columns doesn't work, because we are not allowed to inject in its events. So you have to create your own checkbox inside the column, with a value of note id.

Selected IDs might be stored inside the viewScope. In the checkbox, you should check or uncheck the checkbox according to the list stored in viewScope.

You also create an RPC control to communicate with the viewscope object in the background. It has to have a single method: rpc.myMethod(noteId, checked). It will get the noteId, add to/delete from the viewScope.

<xp:viewColumn id="viewColumn3" displayAs="hidden">
<xp:this.facets>
    <xp:viewColumnHeader xp:key="header" id="viewColumnHeader3"></xp:viewColumnHeader>
</xp:this.facets>
<input class="xspCheckBoxViewColumn" type="checkbox" value="#{javascript:viewEntry.getNoteID()}" style="margin: 0px 2px; height: 12px;" onChange="rpc.myMethod(this.value, this.checked)"/></xp:viewColumn>

Hope this helps.



来源:https://stackoverflow.com/questions/9513892/how-to-keep-selection-when-paging-thru-a-view

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!