Grid Control - Sorting Issues

Started by JMack, January 31, 2008, 04:33:46 PM

Previous topic - Next topic

JMack

[OpenDCL Studio 4.1.2.1]

Hello everyone,

I'm having a hell of a time trying to sort my Grid control. Here are are my issues;
1.  Grid control only sorts ascending. I'm using the column click event and to init the sort.  I've ried T/nil and 1/0.
2.  When the grid does sort (ascending only), it only sorts text cells.  It ignores Check Boxes and AcadColor cells.  I've used dcl_Grid_SortNumericItems and dcl_Grid_SortTextItems. The AcadColor cell gets all messed up, the colors change.

I've debugged the hell out of my code and confirmed its passing the correct arguments.

Let me know if you've used this control and got it sorting properly.  Also let me know if you have had problems with sorting Check Boxes and AcadColor cells.
Thats it.  Theres a pic of my grid at the bottom.

Cheers,
JMack

If your wondering about my code, here's a snippet (I don't expect anyone to understand any of it)

(defun HDF_ODCLGrid_Sort (strFunction strGrid eGrid iColumn / iSortColumn iSortOrder)
  (cond
    ((null iColumn)(HDF_ODCLGrid_InitSort strFunction strGrid eGrid))
    ((eq 1 (HDF_ODCLGrid_RegGetColumn strFunction strGrid iColumn "sortable"))
     (setq
       iSortColumn (HDF_ODCLGrid_RegGet strFunction strGrid "SortColumn")
       iSortOrder  (HDF_ODCLGrid_RegGet strFunction strGrid "SortOrder")
     )
     (if
       (eq iSortColumn iColumn)
       (if
         (eq iSortOrder 1)
         (setq iSortOrder 0)
         (setq iSortOrder 1)
       )
       (setq iSortColumn iColumn iSortOrder 1)
     )
     (HDF_ODCLGrid_RegPut strFunction strGrid "SortColumn" iSortColumn)
     (HDF_ODCLGrid_RegPut strFunction strGrid "SortOrder" iSortOrder)
     (HDF_ODCLGrid_InitSort strFunction strGrid eGrid)
   )
   (T nil);columns not sortable
  )
  nil
)

(defun HDF_ODCLGrid_InitSort (strFunction strGrid eGrid / iSortColumn iSortOrder)
  (setq
    iSortColumn (HDF_ODCLGrid_RegGet strFunction strGrid "SortColumn")
    iSortOrder  (HDF_ODCLGrid_RegGet strFunction strGrid "SortOrder")
  )
  (HDC_Debug_Print (strcat "\niSortColumn: " (vl-princ-to-string iSortColumn) ", " "iSortOrder: " (vl-princ-to-string iSortOrder)))
  (if
    (member (HDF_ODCLGrid_RegGetColumn strFunction strGrid iSortColumn "style") (list 1 8 30 31));;is this a numeric column?
    (dcl_Grid_SortNumericItems eGrid iSortColumn (eq 1 iSortOrder))
    (dcl_Grid_SortTextItems eGrid iSortColumn (eq 1 iSortOrder))
  )
  nil
)





[attachment deleted by admin]

owenwengerd

The grid cell sorting code was the one part of the original grid code that I didn't rewrite, and it's a mess. If you can, please send me a small sample project and lisp code to reproduce the problem. Also, I'd like to hear from anyone else that is familiar with sorting to explain whether this problem with toggle cells being ignored is a bug or by design.

JMack

#2
Heres some code to test with.

Columns definition is
(list
      (list 0 "idx" 1 24)
      (list 1 "6 - Strings (1)" 1 75)
      (list 2 "1 - Check Boxes" 1 75)
      (list 3 "30 - AcadColor" 1 75)
      (list 4 "6 - Strings (2)" 1 75)
      (list 5 "8 - Integers" 1 75)
      (list 6  "9 - Units" 1 75)
    )

You'll notice how the check boxes do nothing and ACADColor goes all white.

Good luck and Thanks.

[attachment deleted by admin]

BazzaCAD

Quote from: owenwengerd on January 31, 2008, 06:23:49 PM
Also, I'd like to hear from anyone else that is familiar with sorting to explain whether this problem with toggle cells being ignored is a bug or by design.

Sounds like a bug to me.
a.k.a.
Barry Ralphs
barryDOTralphsATgmailDOTcom

owenwengerd

Quote from: JMack on January 31, 2008, 07:44:43 PM
Heres some code to test with.

Thanks for the excellent sample! That makes my job much easier. I've rewritten the sorting functions for Alpha 3, and your sample is now working fine in my tests.

The original sorting code did a lot of things that are no longer relevant or necessary. Rather than spend time trying to unravel how it was originally intended to work, I just wrote new functions that work the way I would expect them to work. Please test these after Alpha 3 is released this weekend and let me know whether you still notice any problems.

JMack

Your the best!  I have many ListView controls I want to convert over to Grid but was concerned about all the bugs. So far my only issue is sorting and it appears you got it under control.

Below is the list of all the cell styles.  When you get a chance can you confirm that I've classified them correctly as strings and numeric items.  If its not that straight forward, no prob, I'll eventually get around to it. I'm a little confused about certain items.  For example AcadColor, will Color 75 be sorted before Color 175.  Thanks again!

         0 - Decide at run time
    1 - Check Boxes - numeric (sorts check state?)
    2 - Option Buttons - numeric (sorts option state?)
    3 - Switchable Icons - numeric (sorts icon index?)
    4 - Ellipses Buttons - text
    5 - Pick Buttons - text   
    6 - Strings - text   
    7 - AngleUnits   - numeric
    8 - Integers - numeric   
    9 - Units - numeric      
   10 - UpperCase   - text
   11 - LowerCase   - text
   12 - Password   - text
   13 - MultiLine   - text
   14 - Currency - numeric
   15 - Date - numeric (hopefully)   
   16 - Time - numeric (hopefully)      
   17 - Percentage   - numeric
   18 - DropDown - text
   19 - ArrowHeads - text
   20 - Acad Colors - numeric (color index?)
   21 - TextStyle List - text
   22 - PlotStyle Names - text
   23 - PlotStyle Tables - text
   24 - Plotter List - text
   25 - Fonts - text   
   26 - Drive List - text
   27 - Layer List   - text
   28 - DimStyle List - text
   29 - ImageDrop List - text (or numeric icon index?)
   30 - AcadColor Cell - numeric (color index?)
   31 - TrueColor Cell - numeric
   32 - LineWeight Cell - numeric (index?)
   33 - Linetype Cell - text   
   34 - Directories - text
   35 - Files - text
   36 - Strings Combo - text
   37 - AngleUnits Combo - numeric
   38 - Integers Combo - numeric
   39 - Units Combo - numeric   
   40 - UpperCase Combo - text
   41 - LowerCase Combo - text

Cheers

owenwengerd

Quote from: JMack on February 01, 2008, 03:22:58 PM
When you get a chance can you confirm that I've classified them correctly as strings and numeric items.  If its not that straight forward, no prob, I'll eventually get around to it. I'm a little confused about certain items.  For example AcadColor, will Color 75 be sorted before Color 175.

Sorting as text or numeric is independent of the cell style. That is, you can sort any style cell using either method. The difference is in the comparison used for the sort. A text sort always sorts using the text value of the cell (i.e. "Color 175" would be ordered before "Color 75"). A numeric sort is based on the following logic: if the cell states are different, it sorts on that; otherwise if the cell images are different it sorts on that; otherwise it converts the cell text to an integer and sorts on that (this means non-numeric values will always evaluate to zero and thus considered equal).

To better understand the practical implications of the numeric sort you need to consider that the image index is used as more than just an image index. In color style cells that contain an ACI color, the image index is the ACI color index (however if the cell contains a true color value, the image index is -1; if it contains a color book color, the image index is -2 -- so color cells with a true color or color book value won't sort correctly using a numeric sort.) In dropdown combo style cells, the image index is the current selection index, so a numeric sort will order the cells in the same order the items appear in the dropdown list.

The sort logic is pretty straightforward, but it probably won't work as desired in all cases. I think dates and times should work with a numeric sort, but I didn't test that. In cases where neither sort method sorts the way you want it to, you could probably create a hidden zero-width column of integers and use that column in concert with the numeric sort to reorder the rows in whatever way you want, using your own custom ordering logic.

JMack

#7
Thanks for the quick reply!  So let me get this straight, to get check boxes sorted by check state I would sort numerically because the cell images are different?

owenwengerd

Quote from: JMack on February 01, 2008, 04:00:09 PM
So let me get this straight, to get check boxes sorted by check state I would sort numerically because the cell images are different?

Actually you would sort numerically because the cell states are different (it sorts first on cell state, then on image index). This is necessary because for some styles (e.g. the Check Boxes style) there is no image index, and the only thing that changes is the cell state (cell state is a value maintained internally by the control).

JMack

Glad I asked because when you said
QuoteA numeric sort is based on the following logic: if the cell states are different,...
I thought you actually meant different cell styles. I didn't realize there was an internal cell state.  I think sorting is all sorted out for now.

Cheers