简体   繁体   English

primefaces单选数据表分页+ rowIndexVar

[英]primefaces single selection datatable pagination + rowIndexVar

I have a datatable with columns containing images. 我有一个包含包含图像的列的数据表。

<p:dataTable id="tabexam"
             lazy="true"
             paginatorPosition="bottom"
             var="exam"
             value="#{dyna.lazyModel}"
             widgetVar="examTable"
             emptyMessage="No results"
             paginator="true"
             rows="#{dyna.rows}" 
             selection="#{dyna.selectedExamen}"
             rowKey="#{exam.studyUid}"
             selectionMode="single"
             rowIndexVar="rowx"
             resizableColumns="false"  
             draggableColumns="true"
             paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"  >

On simple text columns when you select a row it gets selected and highlighted correctly. 在简单文本列上,当您选择一行时,它将被正确选中并突出显示。

The problem is with columns that contain p:graphicimage: 问题在于包含p:graphicimage的列:

<p:column headerText="#{column.userListname}"
          sortBy="#{column.dbname}"
          filterBy="#{column.dbname}"
          filterMatchMode="exact" 
          style="#{column.visible==true? 'text-align:center!important;vertical-align: middle!important;':'display:none!important;'}"
          width="#{column.visible==true? 16:0}"
          resizable="#{column.visible==true? column.resizable:false}" 
          rendered="#{column.dbname == 'studyPatientState'}">

           <p:graphicImage value="/images/study_State_icons/#{exam.studyPatientState}.png" styleClass="imagero"
                          onclick="examTable.unselectAllRows();
                                        examTable.selectRow(#{rowx});"/>
</p:column>

As you see in order to highlight rows on graphicImage click, i had to add this js: 如您所见,为了突出显示graphicImage click上的行,我不得不添加以下js:

onclick="examTable.unselectAllRows();examTable.selectRow(#{rowx});"

The problem is when i switch to another page those js functions cease to work. 问题是当我切换到另一个页面时,那些js函数停止工作。

I have noticed that in order this to work i need to reset the rowIndexVar for every page, but how may implement such thing. 我已经注意到,为了使其正常工作,我需要为每个页面重置rowIndexVar,但是如何实现这种方法。

what am doing wrong here ? 这是怎么了?

There is one more alternative here using JQuery, try this. 使用JQuery还有另外一种选择,尝试一下。

onclick="clickParent(this)"

<script type="text/javascript">

   function clickParent(imgElement){
     var tdElement = $(imgElement).parents("td");
     $(tdElement).click()
   }
</script>

The above approach will send the Image element to the fuinction, the function will seach through the Parents until it reaches the TD element and Invokes the click event on the td . 上面的方法将把Image元素发送到函数,该函数将遍历Parents直到到达TD元素并在td上调用click事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM