Curl Global Community
Sort of RecordView - Printable Version

+- Curl Global Community (https://communities.curl.com)
+-- Forum: Discussions (https://communities.curl.com/forumdisplay.php?fid=1)
+--- Forum: General Curl questions (https://communities.curl.com/forumdisplay.php?fid=2)
+--- Thread: Sort of RecordView (/showthread.php?tid=652)



Sort of RecordView - alchimiste - 11-21-2012

Hi, everybody

When RecordView is sorted, the specific Record must not be sorted.
For example,
----------------------------------------
LOTID | HOLD | RUN | WAIT
----------------------------------------
AAAA | 200 | 100 | 50
BBBB | 300 | 50 | 30
TOTAL | 500 | 150 | 80
----------------------------------------
the Record of TOTAL must not be sorted and it must be always in the bottom of RecordView.
I tried to use RecordSort object but it did not work as I wished.






RE: Sort of RecordView - fukuta - 11-21-2012

Which column would you like to sort by?
How did you try to do that?
It may help if you show us the code we can reproduce the problem.


RE: Sort of RecordView - ashimo - 11-21-2012

How about this?

Code:
{curl 7.0 applet}

{let people:RecordSet =
    {RecordSet
        {RecordFields
            {RecordField "First", domain = String},
            {RecordField "Last", domain = String},
            {RecordField "Age", domain = int},
            || hidden field
            {RecordField "hidden", domain = int}
        },
        || hidden = 0
        {RecordData First = "Gene", Last = "Smith", Age = 25, hidden = 0},
        {RecordData First = "Fred", Last = "Smith", Age = 29, hidden = 0},
        {RecordData First = "Mike", Last = "Jones", Age = 28, hidden = 0},
        {RecordData First = "Ben", Last = "Abrams", Age = 25, hidden = 0},
        {RecordData First = "Ben", Last = "Smith", Age = 21, hidden = 0},
        {RecordData First = "Sam", Last = "Jones", Age = 22, hidden = 0},
        {RecordData First = "Nigel", Last = "Stevens", Age = 24, hidden = 0},
        {RecordData First = "Bert", Last = "Stevens", Age = 22, hidden = 0},
        {RecordData First = "Pat", Last = "Linden", Age = 27, hidden = 0},
        || hidden = 1
        {RecordData First = "TOTAL", Last = "", Age = 25+29+28, hidden = 1}
    }
}
{let asc?:bool = true}
{let last-sort-column:String = ""}

{def rg = {RecordGrid
              record-source = people,
              height = 10cm,
              automatic-columns? = false,
              {RecordGridColumn "First"},
              {RecordGridColumn "Last"},
              {RecordGridColumn "Age"},

              sort = {RecordSort.from-string "hidden, Age"},
              sort-spec = {proc {rgc:RecordGridColumn}:RecordSort
                              {if last-sort-column != rgc.field-name then
                                  set asc? = true
                              }
                              let rs:RecordSort =
                                  {RecordSort.from-string
                                      "hidden " &
                                      {if asc? then
                                          "asc"
                                       else
                                          "desc"
                                      }
                                      & ", " & rgc.field-name
                                  }
                              || Store column name and sort order.
                              set last-sort-column = rgc.field-name
                              set asc? = not asc?
                              {return rs}
                          }
          }
}
{value rg}



RE: Sort of RecordView - alchimiste - 11-21-2012


The TOTAL record should not be sorted for all columns.


Users want to see the summary record such as TOTAL or AVERAGE.
The summary record usually is located in the bottom of RecordView.

I'm implementing this for the grid component, modified FastRecordGrid.

The source code that I wrote:

def rd = rv[rv.size - 1] || rv is RecordView
set rv.sort = {proc {r1:Record, r2:Record}:int
|| I thnk this code is stupid...Smile
{if r1 == rd then {return 1}}
|| the rest of logics is omitted for explanation
}