Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Sorting

    Hi,
    My code needs to do a fetch and get a list back in a certain order. I see in DSRequest there is a call to setSortBy(). What is the sort order (ascending/descending) when this is called? Is there a way to specify the sort order? Also if the code just need to fetch the top record (smallest record index), how should the criteria be specified?
    Thanks,
    KL

    #2
    Hi khanhlam,

    I'm pretty sure you are talking about the serverside DSRequest, correct? Clientside DSRequest is pretty obvious with the SortSpecifier.
    Serverside, a "-" as prefix makes the sort descending (see the docs). NULLS FIRST/LAST is not possible, but you can add notNull criteria.
    If you want to limit the result, see setEndRow().

    Best regards
    Blama

    Comment


      #3
      Hi,
      Yes, this is server side DSRequest. Sorry I don't quite understand your answers.
      Just want to clarify. So the DSRequest.setSortBy(fieldname) defaults to ascending, and DSRequest.setSortBy(-fieldname) is for descending. Is this correct?
      The setEndRow() sets the index of the last requested record. But the code doesn't know about the index values. It just need to fetch the top record (smallest record id). For example, if there are 3 records with record ids of 3, 10, 15. The fetch should return the record with id 3. How would the criteria be specified?

      Thanks,
      KL

      Comment


        #4
        Hi khanhlam,

        DSRequest.setSortBy(-fieldname) is for descending
        Correct.

        The fetch should return the record with id 3. How would the criteria be specified?
        Code:
        myRequest.setSortBy("idField");
        myRequest.setEndRow(1);
        
        This should result in following SQL:
        SELECT ... FROM ... ORDER BY idField LIMIT 1;
        Just try it and see what happens in the IDE console output.

        Best regards
        Blama

        Comment


          #5
          Hi,
          Got it. It's clear now. Thanks. For the setEndRow(value), I thought the value (in this example) is 3, which is not known by the code. But it's the number(LIMIT) of returned records .
          Thanks,
          KL

          Comment

          Working...
          X