Sorting a drop-down list - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Sorting a drop-down list

Last post 01-07-2010 07:30 AM by kcoakley. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 01-05-2010 10:02 AM

    Sorting a drop-down list

    Hello and thanks for such a great resource!

    What I'm trying to do: I'm pulling a list of employee names from a secondary data source (web service) into a drop-down list. I would like to have the list sorted alphabetically, but it doesn't appear that InfoPath supports this directly.

    I have searched these forums and thought I found a solution - adding the "xsl:sort" element to my view1.xsl file. But I must be missing something because the drop-down list does not appear sorted when I preview it. Here is the block of code I've modified: (my addition is in bold)

    <xsl:for-each select="xdXDocument:GetDOM(&quot;GetEmployeeList&quot;)/dfs:myFields/dfs:dataFields/s0:GetEmployeeListResponse/s0:GetEmployeeListResult/ns1:SqlRowSet1/ns1:row1/ns1:EmployeeName">
             <xsl:sort/>
             <option>
              <xsl:attribute name="value">
               <xsl:value-of select="."/>
              </xsl:attribute>
              <xsl:if test="$val=.">
               <xsl:attribute name="selected">selected</xsl:attribute>
              </xsl:if>
              <xsl:value-of select="."/>
             </option>
            </xsl:for-each>

    Should this work as I'm expecting it to? What am I doing wrong?

    Thanks again!
    Ken

  • 01-06-2010 08:17 AM In reply to

    Re: Sorting a drop-down list

    Hi Anuma, and thanks for your response!

    I have gone through the links you provided and am still unable to get the sort to work. Based upon what I've read above, there appear to be two ways to accomplish this sort:

     1. Using the "xsl:sort" element in the view.xsl file. (This is what I tried to do with the code shown in my original post.) Your first link seems to suggest that this should work, but that I may need a "Preserve Code Block." However, as I understand it, the "Preserve Code Block" is only needed to prevent InfoPath from stripping out the unsupported code if I use the InfoPath Designer after manually adding the "xsl:sort." Shouldn't I be able to manually add the "xsl:sort" element and then preview the form to see that it is working without having to add the "Preserve Code Block?" That said, however, I did add the "Preserve Code Block" and still did not accomplish the sort.

     2. Coding the sort. I've looked at the code examples and tried a few but none seem to work for me. (My error, I am sure.) I am still learning to code for InfoPath and this is a bit beyond my ability right now.

     So I guess my current question is: should the "xsl:sort" element be working for this drop-down list as coded in my original post? If not, what is the next easiest way to accomplish this?

     Thanks again!
    Ken

  • 01-06-2010 01:54 PM In reply to

    Re: Sorting a drop-down list

    I'm also new to InfoPath but in my case I'm using Access as my secondary datasource and sorting the items is very very easy. Just a matter of selecting some options in Tools / Data Connections. I'm not sure if the same can be done with web service as the secondary datasource because I haven't tried that yet.

  • 01-06-2010 04:30 PM In reply to

    Re: Sorting a drop-down list

     If you have any way of receiving the data in a sorted form like ricomarcelo suggested, that may be the easiest approach.

    As for getting your xsl:sort to work, maybe it's not working because there's no select attribute? (It should work without one though...) Or is it possible you're making a small change in the designer and not realizing it before previewing the form and that's obliterating the xsl:sort.

    I'm not 100% sure, but I don't think that a Preserve Code Block is the solution here, because I think Preserve Code Blocks can only display data, and not contain data-bound controls.  I could be mistaken though.

     For an easy-to-use alternative to using code, try out qRules. It provides a SortTable feature, that can sort the data in your secondary data source with just one command.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 01-07-2010 07:22 AM In reply to

    Re: Sorting a drop-down list

     Hi ricomarcelo and thanks for your suggestion... I poked through the secondary datasource options for the web service and don't see any sorting choices at all. Maybe I'm just missing something, but other sources I've read seem to suggest that there isn't a simple solution in this circumstance.

    Thanks!
    Ken

  • 01-07-2010 07:30 AM In reply to

    Re: Sorting a drop-down list

     Jimmy - thanks for your reply.

    I'm fairly certain that my xsl:sort is right and is not being removed by InfoPath. These are the steps I'm taking:

    1. I edit the view1.xsl file and add the "xsl:sort" element. (I tried it with and without the "select" attribute.) Save & close.
    2. I right click the .xsn file and choose Open. This opens the form in InfoPath (not in designer mode). The drop-down list is not sorted. Exit.
    3. If I look back at the view1.xsl file, the "xsl:sort" element is still there.

    Does that sound right?

    Thanks for the qRules suggestion - I'm going to give that a try next. And the other alternative, as you point out, is to go back to the data source and do the sort on that end.

    Thanks again,
    Ken

Page 1 of 1 (7 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.