how to get the correct item in the model, after sorting in a repeat

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

how to get the correct item in the model, after sorting in a repeat

Myxlyxl
Hello,

my problem:

I use exf:sort to sort a repeat:

<xforms:repeat nodeset="exf:sort(instance('main-instance')/Calls/Call/Servicerufnummern/SRN,'@ID','text')" id="N10028-repeat">

</xforms:repeat>

somewhere later (not in the above repeat) I have a trigger to delete an element from the repeat:

<xforms:trigger appearance="minimal">
<xforms:action ev:event="DOMActivate">
<xforms:delete at="index('N10028-repeat')" ev:event="DOMActivate" context="instance('main-instance')/Calls/Call/Servicerufnummern" nodeset="SRN" />
 </xforms:action>
<xforms:label>
 -
        SRN
</xforms:label>
</xforms:trigger>

The problem is, that index('N10028-repeat') doesnt provide the correct index. It gives me the correct index of the selected item, but this is not the same as in the model because of the sort. Without sorting everything works perfect.

I also tried something like: count(instance('main-instance')/Calls/Call/Servicerufnummern/SRN[index('N10028-repeat')]/preceding-sibling::SRN)+1] , no luck either.

Perhaps somebody has an idea how to get the correct index ?

Thanks a lot
Michael
Reply | Threaded
Open this post in threaded view
|

Re: how to get the correct item in the model, after sorting in a repeat

Erik Bruchez
Administrator
Michael,

That's right, the index returned by index() is that of the resulting  
node-set, not that of the node-set before using exf:sort().

What you could do is redo the sorting in the delete action, something  
like this:

<xforms:delete ev:event="DOMActivate" at="index('N10028-repeat')"
   nodeset="ef:sort(instance('main-instance')/Calls/Call/
Servicerufnummern/SRN,'@ID','text'"/>

-Erik

On Jun 3, 2009, at 4:06 AM, Myxlyxl wrote:

>
> Hello,
>
> my problem:
>
> I use exf:sort to sort a repeat:
>
> <xforms:repeat
> nodeset="exf:sort(instance('main-instance')/Calls/Call/
> Servicerufnummern/SRN,'@ID','text')"
> id="N10028-repeat">
>
> </xforms:repeat>
>
> somewhere later (not in the above repeat) I have a trigger to delete  
> an
> element from the repeat:
>
> <xforms:trigger appearance="minimal">
> <xforms:action ev:event="DOMActivate">
> <xforms:delete at="index('N10028-repeat')" ev:event="DOMActivate"
> context="instance('main-instance')/Calls/Call/Servicerufnummern"
> nodeset="SRN" />
> </xforms:action>
> <xforms:label>
> /img/remove.gif
>        SRN
> </xforms:label>
> </xforms:trigger>
>
> The problem is, that index('N10028-repeat') doesnt provide the correct
> index. It gives me the correct index of the selected item, but this  
> is not
> the same as in the model because of the sort. Without sorting  
> everything
> works perfect.
>
> I also tried something like:
> count(instance('main-instance')/Calls/Call/Servicerufnummern/
> SRN[index('N10028-repeat')]/preceding-sibling::SRN)+1]
> , no luck either.
>
> Perhaps somebody has an idea how to get the correct index ?
>
> Thanks a lot
> Michael
>
> --
> View this message in context: http://www.nabble.com/how-to-get-the-correct-item-in-the-model%2C-after-sorting-in-a-repeat-tp23848200p23848200.html
> Sent from the ObjectWeb OPS - Users mailing list archive at  
> Nabble.com.
>
>
> --
> You receive this message as a subscriber of the [hidden email]  
> mailing list.
> To unsubscribe: mailto:[hidden email]
> For general help: mailto:[hidden email]?subject=help
> OW2 mailing lists service home page: http://www.ow2.org/wws
--
Orbeon Forms - Web Forms for the Enterprise Done the Right Way
http://www.orbeon.com/



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: how to get the correct item in the model, after sorting in a repeat

Alessandro Vernet
Administrator
Michael,

Erik Bruchez wrote
What you could do is redo the sorting in the delete action, something  
like this:

<xforms:delete ev:event="DOMActivate" at="index('N10028-repeat')"
   nodeset="ef:sort(instance('main-instance')/Calls/Call/
Servicerufnummern/SRN,'@ID','text'"/>
And if you want to avoid repeating that expression, you can use a variable:

<xxforms:variable name="sorted-nodeset" select="exf:sort(instance('main-instance')/Calls/Call/Servicerufnummern/SRN,'@ID','text')"/>
<xforms:repeat nodeset="$sorted-nodeset" id="N10028-repeat">
    <xforms:trigger appearance="minimal">
        <xforms:action ev:event="DOMActivate">
            <xforms:delete at="index('N10028-repeat')" ev:event="DOMActivate"
                           nodeset="$sorted-nodeset"/>
        </xforms:action>
    </xforms:trigger>
</xforms:repeat>

Alex
Reply | Threaded
Open this post in threaded view
|

Re: how to get the correct item in the model, after sorting in a repeat

Myxlyxl
In reply to this post by Myxlyxl
Thank you all,

that helped to solve my problem.


Michael

Myxlyxl wrote
Hello,

my problem:

I use exf:sort to sort a repeat:

<xforms:repeat nodeset="exf:sort(instance('main-instance')/Calls/Call/Servicerufnummern/SRN,'@ID','text')" id="N10028-repeat">

</xforms:repeat>

somewhere later (not in the above repeat) I have a trigger to delete an element from the repeat:

<xforms:trigger appearance="minimal">
<xforms:action ev:event="DOMActivate">
<xforms:delete at="index('N10028-repeat')" ev:event="DOMActivate" context="instance('main-instance')/Calls/Call/Servicerufnummern" nodeset="SRN" />
 </xforms:action>
<xforms:label>
 -
        SRN
</xforms:label>
</xforms:trigger>

The problem is, that index('N10028-repeat') doesnt provide the correct index. It gives me the correct index of the selected item, but this is not the same as in the model because of the sort. Without sorting everything works perfect.

I also tried something like: count(instance('main-instance')/Calls/Call/Servicerufnummern/SRN[index('N10028-repeat')]/preceding-sibling::SRN)+1] , no luck either.

Perhaps somebody has an idea how to get the correct index ?

Thanks a lot
Michael
Reply | Threaded
Open this post in threaded view
|

Re: how to get the correct item in the model, after sorting in a repeat

                                                                                                                                                                                                                                                                   </xhtml:tr>
                                        <xxforms:variable name="sorted-nodeset" select="exf:sort(instance('clinicalExamniationInstance')/consls/consl,'ConslDate','text')"/> 
                                        <xforms:repeat id="consultation" model="clinicalExaminationModel"
                                                                                nodeset="$sorted-nodeset">
                                                                                                                                                                                                                                                                                                                                                                                                                                                              </xforms:repeat>

                                  </xhtml:table>
lakshmipmandava
Similar way i am trying to implementing for edit feature and not working.Not able to get correct index after sorting using xxforms:sort or exsort

suggest how do i go about to fix issue

 <xhtml:table width="99%">
                                        <xhtml:tr>
                                           
DateDoctor NameComplaintPrescribed Medicines<br/>
                                                    (Name|Dosage|days)
Prescribed TestsAction
                                                <xforms:output model="clinicalExaminationModel" ref="ConslDate"/><xforms:output model="clinicalExaminationModel" ref="Doc" />                                               <xforms:output model="clinicalExaminationModel" ref="HP" class="item-amount" />
                                           
                                                                                                      <xforms:repeat model="clinicalExaminationModel" nodeset="Medicines/Medicine">
                                                                                                                                                                                                                                                                                                                                                  </xforms:repeat>
                                                 
                                                            <xforms:output model="clinicalExaminationModel" ref="Name" class="item-amount" />
                                                         
                                                            <xforms:output model="clinicalExaminationModel" ref="Dosage" class="item-amount" />
                                                         
                                                            <xforms:output model="clinicalExaminationModel" ref="Duration" class="item-amount" />
                                                         
                                           
                                                <xforms:repeat model="clinicalExaminationModel" nodeset="Tests/test">
                                                                                                                                                                                                                                                                                     
                                                              <xforms:output model="clinicalExaminationModel" ref="@name" class="item-amount" />
                                                           
                                                </xforms:repeat>
                                           
                                                <xforms:trigger appearance="minimal">
                                                    <xforms:label><xhtml:img src="/media/icons/document_edit.png" width="20px" alt="Edit" title="Edit Consultation"/></xforms:label>
                                                    <xforms:toggle case="c022" ev:event="DOMActivate" />
                                                    <xforms:action ev:event="DOMActivate">
                                               
                                                        <xforms:setvalue ref="/lists/list[index('list')]/todo[index('todo')]/@ui:mode" value="'edit'"/>
                                                        <xforms:setvalue ref="instance('consl-num')/consl" value="index('consultation')" />
                                                        <xforms:setvalue ref="instance('consultation-index')/@val" value="index('consultation')" />
                                                        <xforms:toggle case="case-3" />
                                                    </xforms:action>
                                                </xforms:trigger>

                                                <xforms:trigger appearance="minimal">
                                                    <xforms:label><xhtml:img src="/media/img/lab.png" width="18px" alt="Test Results" title="Test Results"/></xforms:label>
                                                    <xforms:action ev:event="DOMActivate">
                                                                <xforms:setvalue ref="instance('consl-num')/consl" value="index('consultation')"/>

                                                                <xforms:setvalue ref="instance('url-container1')" value="concat('/${pageContext.request.contextPath}/strts/crmsPage?department=rheumatology&amp;pageName=lab.jsp&amp;cardId=<%= request.getParameter("cardId") %>', instance('user-name'))"/>
                                                                <xforms:setvalue ref="instance('url-container1')" value="concat(instance('url-container1'), '&amp;conslDate=')"/>
                                                                <xforms:setvalue ref="instance('url-container1')" value="concat(instance('url-container1'), instance('clinicalExamniationInstance')/consls/consl[number(instance('consl-num')/consl)]/ConslDate)"/>
                                                                <xforms:load ref="instance('url-container1')" show="replace" ev:event="DOMActivate"/>

                                                    </xforms:action>
                                                </xforms:trigger>
                                               
                                                                                        <xforms:setvalue ref="@modified" value="seconds-from-dateTime(now())" ev:event="xforms-value-changed" />
                                             
Reply | Threaded
Open this post in threaded view
|

Re: Re: how to get the correct item in the model, after sorting in a repeat

Erik Bruchez
Administrator
You don't really explain your issue.

The repeat index is a user-facing notion. So it will be the index after sorting. E.g. 3 items:

<foo>a</foo>
<foo>b</foo>
<foo>c</foo>

sorted in descending order will show in the UI:

c
b
a

If the first row is selected by the user, the index is 1,  not 3.

If you need to know the position of a given element in the instance, you can always count elements, e.g.:

count(preceding-sibling::foo) + 1

-Erik

On Tue, Jan 25, 2011 at 8:48 PM, lakshmipmandava <[hidden email]> wrote:

Similar way i am trying to implementing for edit feature and not working.Not
able to get correct index after sorting using xxforms:sort or exsort

suggest how do i go about to fix issue

 <xhtml:table width="99%">
                                       <xhtml:tr>
                                           <th width="10%"
class="datatable_th_xforms">Date</th>
                                           <th width="12%"
class="datatable_th_xforms">Doctor Name</th>
                                           <th width="17%"
class="datatable_th_xforms">Complaint</th>
                                           <th width="30%"
class="datatable_th_xforms">Prescribed Medicines<br/>
                                                   (Name|Dosage|days)</th>
                                           <th width="20%"
class="datatable_th_xforms">Prescribed Tests</th>
                                           <th width="15%"
class="datatable_th_xforms">Action</th>
                                      </xhtml:tr>
                                       <xxforms:variable name="sorted-nodeset"
select="exf:sort(instance('clinicalExamniationInstance')/consls/consl,'ConslDate','text')"/>
                                       <xforms:repeat id="consultation" model="clinicalExaminationModel"
                                                                               nodeset="$sorted-nodeset">
                                       <tr>
                                           <td width="10%"
class="datatable_td_xforms">
                                               <xforms:output model="clinicalExaminationModel"
ref="ConslDate"/></td>
                                           <td width="12%"
class="datatable_td_xforms"><xforms:output model="clinicalExaminationModel"
ref="Doc" /></td>
                                           <td width="17%"
class="datatable_td_xforms">
                                              <xforms:output
model="clinicalExaminationModel" ref="HP" class="item-amount" />
                                           </td>
                                           <td width="30%"
class="datatable_td_xforms">
                                                 <table width="100%">
                                                   <xforms:repeat model="clinicalExaminationModel"
nodeset="Medicines/Medicine">
                                                       <tr>
                                                         <td width="50%">
                                                           <xforms:output model="clinicalExaminationModel" ref="Name"
class="item-amount" />
                                                         </td>
                                                         <td width="20%">
                                                           <xforms:output model="clinicalExaminationModel" ref="Dosage"
class="item-amount" />
                                                         </td>
                                                         <td width="20%">
                                                           <xforms:output model="clinicalExaminationModel" ref="Duration"
class="item-amount" />
                                                         </td>
                                                       </tr>
                                                   </xforms:repeat>
                                                </table>
                                           </td>
                                           <td width="20%"
class="datatable_td_xforms">
                                               <xforms:repeat
model="clinicalExaminationModel" nodeset="Tests/test">
                                                   <table width="100%">
                                                       <tr>
                                                           <td>
                                                             <xforms:output model="clinicalExaminationModel" ref="@name"
class="item-amount" />
                                                           </td>
                                                       </tr>
                                                     </table>
                                               </xforms:repeat>
                                           </td>
                                           <td width="15%"
class="datatable_td_xforms">
                                               <xforms:trigger
appearance="minimal">
                                                   <xforms:label><xhtml:img
src="/media/icons/document_edit.png" width="20px" alt="Edit" title="Edit
Consultation"/></xforms:label>
                                                   <xforms:toggle
case="c022" ev:event="DOMActivate" />
                                                   <xforms:action
ev:event="DOMActivate">

                                                       <xforms:setvalue
ref="/lists/list[index('list')]/todo[index('todo')]/@ui:mode"
value="'edit'"/>
                                                       <xforms:setvalue
ref="instance('consl-num')/consl" value="index('consultation')" />
                                                       <xforms:setvalue
ref="instance('consultation-index')/@val" value="index('consultation')" />
                                                       <xforms:toggle
case="case-3" />
                                                   </xforms:action>
                                               </xforms:trigger>

                                               <xforms:trigger
appearance="minimal">
                                                   <xforms:label><xhtml:img
src="/media/img/lab.png" width="18px" alt="Test Results" title="Test
Results"/></xforms:label>
                                                   <xforms:action ev:event="DOMActivate">
                                                               <xforms:setvalue ref="instance('consl-num')/consl"
value="index('consultation')"/>

                                                               <xforms:setvalue ref="instance('url-container1')"
value="concat('/${pageContext.request.contextPath}/strts/crmsPage?department=rheumatology&pageName=lab.jsp&cardId=<%=
request.getParameter("cardId") %>', instance('user-name'))"/>
                                                               <xforms:setvalue ref="instance('url-container1')"
value="concat(instance('url-container1'), '&conslDate=')"/>
                                                               <xforms:setvalue ref="instance('url-container1')"
value="concat(instance('url-container1'),
instance('clinicalExamniationInstance')/consls/consl[number(instance('consl-num')/consl)]/ConslDate)"/>
                                                               <xforms:load ref="instance('url-container1')" show="replace"
ev:event="DOMActivate"/>

                                                   </xforms:action>
                                               </xforms:trigger>
                                              <!-- <xforms:trigger
appearance="minimal">

<xforms:label>FollowUps</xforms:label>
                                                   <xforms:toggle
case="c022" ev:event="DOMActivate" />
                                                   <xforms:action
ev:event="DOMActivate">
                                                       <xforms:setvalue
ref="instance('consl-num')/consl"       value="index('consultation')" />
                                                       <xforms:setvalue
ref="instance('url-container1')" value="concat('?q=followup_details/',
instance('user-name'))" />
                                                       <xforms:setvalue
ref="instance('url-container1')" value="concat(instance('url-container1'),
'/')" />
                                                       <xforms:setvalue
ref="instance('url-container1')" value="concat(instance('url-container1'),
instance('clinicalExamniationInstance')/consls/consl[number(instance('consl-num')/consl)]/ConslDate)"
/>
                                                       <xforms:send
submission="s111"/>
                                                   </xforms:action>
                                               </xforms:trigger>-->
                                                                                       <xforms:setvalue ref="@modified"
value="seconds-from-dateTime(now())" ev:event="xforms-value-changed" />
                                             </td>
                                                                         </tr>
                                                                   </xforms:repeat>

                                 </xhtml:table>
--
View this message in context: http://orbeon-forms-ops-users.24843.n4.nabble.com/how-to-get-the-correct-item-in-the-model-after-sorting-in-a-repeat-tp43833p3237457.html
Sent from the Orbeon Forms (ops-users) mailing list archive at Nabble.com.


--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws




--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Re: how to get the correct item in the model, after sorting in a repeat

lakshmipmandava
thanks, it work perfectly.