View Issue Details

IDProjectCategoryView StatusLast Update
0036281LazarusWidgetsetpublic2020-01-19 13:26
ReporterChris Rorden Assigned ToDmitry Boyarintsev  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
PlatformMacBook 2012 Retina 13"OSDarwin 
Product Version2.0.7 (SVN) 
Summary0036281: Cocoa: Feature request for ListView SortIndicator
DescriptionThis is a want not need, as this feature does not exist with Lazarus on Windows or Linux. However, it would make Tables in MacOS look more native. It would be great if the Cocoa ListViews could show a SortIndicator at the top of the column used for a sort. Ryan Joseph wrote a skeleton code to implement this (see attached screenshot), and it would be great if this indicated the column that was sorted and the sort direction.
Additional Informationtype
  TCustomTableHeaderCell = objcclass (NSTableHeaderCell)
    listView: TListView;
    procedure drawSortIndicatorWithFrame_inView_ascending_priority (cellFrame: NSRect; controlView_: NSView; ascending: boolean; priority: NSInteger); override;
  end;

procedure TCustomTableHeaderCell.drawSortIndicatorWithFrame_inView_ascending_priority (cellFrame: NSRect; controlView_: NSView; ascending: boolean; priority: NSInteger);
begin
  // manually set the ascending flag to match the current sorting order in the TListView
  inherited drawSortIndicatorWithFrame_inView_ascending_priority(cellFrame, controlView_, false{listView.SortDirection=sdAscending}, priority);
end;

class procedure TCocoaWSCustomListView.ColumnInsert(const ALV: TCustomListView;
  const AIndex: Integer; const AColumn: TListColumn);
var
  lTableLV: TCocoaTableListView;
  lNSColumn: NSTableColumn;
  lTitle: NSString;
  sc: TCocoaListView;
begin
  {$IFDEF COCOA_DEBUG_LISTVIEW}
  WriteLn(Format('[TCocoaWSCustomListView.ColumnInsert] ALV=%x AIndex=%d', [PtrInt(ALV), AIndex]));
  {$ENDIF}
  ALV.HandleNeeded();
  //if not Assigned(ALV) or not ALV.HandleAllocated then Exit;
  //lTableLV := TCocoaTableListView(TCocoaListView(ALV.Handle).documentView);
  if not CheckParams(sc, lTableLV, ALV) then Exit;
  {$IFDEF COCOA_DEBUG_LISTVIEW}
  WriteLn(Format('[TCocoaWSCustomListView.ColumnInsert]=> tableColumns.count=%d', [lTableLV.tableColumns.count()]));
  {$ENDIF}
  if (AIndex < 0) or (AIndex >= lTableLV.tableColumns.count()+1) then Exit;
  lTitle := NSStringUTF8(AColumn.Caption);
  lNSColumn := NSTableColumn.alloc.initWithIdentifier(lTitle);

  // set custom header cell
  lNSColumn.setHeaderCell(TCustomTableHeaderCell.alloc.init);
  lNSColumn.headerCell.setStringValue(lTitle);
  // set a reference to the TListView but I'm not sure how
  TCustomTableHeaderCell(lNSColumn.headerCell).listView := nil;
  // set the NSSortDescriptor so NSTableView draws the arrows
  lNSColumn.setSortDescriptorPrototype(NSSortDescriptor.sortDescriptorWithKey_ascending(lNSColumn.identifier, true));

  lNSColumn.setResizingMask(NSTableColumnUserResizingMask);

  lTableLV.addTableColumn(lNSColumn);
  lTitle.release;
end;
TagsNo tags attached.
Fixed in Revision62567
LazTarget-
WidgetsetCocoa
Attached Files

Activities

Chris Rorden

2019-11-07 21:22

reporter  

sort.png (5,218 bytes)   
sort.png (5,218 bytes)   

Dmitry Boyarintsev

2020-01-10 03:44

developer   ~0120294

description:
https://wiki.freepascal.org/TListView#Proposed:_Sort_Indicator

a feature is available here:
https://svn.freepascal.org/svn/lazarus/branches/listviewsortindicator

it's not in the trunk yet, so please test. (if desired Win32, Gtk2, Qt5 are also available).

Chris Rorden

2020-01-12 01:13

reporter   ~0120348

Wow. This looks really impressive. The cross-platform abilities look terrific. I am on the road, and will not be able to test this for a week or so. I would be grateful if others could try this out. I think this will be a great feature for the community. Cross platform is certainly desired!

Dmitry Boyarintsev

2020-01-17 02:50

developer   ~0120490

please test and close if ok.

the documentation for the description is available on the wiki (at the given links)
as well as lazarus docs have been updated (you might want to rebuild docs as well)

Chris Rorden

2020-01-19 02:00

reporter   ~0120527

This is an amazing feature! Perhaps you want me to create a new issue, but this new feature makes me want to set the "AutoSort" and "AutoSortIndicator" to TRUE. Using svn 62571 on my MacOS, I have a form where some columns are numeric and others are strings. I would have thought setting the "SortType" to "stBoth" would automatically detect which columns are text and which are numeric, but this option appears to sort columns as strings regardless of their datatype, such that "101" is less than "22" and "99.2" is greater than "160.2". Is there some way to either auto-detect the sort type or let the user specify the SortType explicitly for each column?
SortData.zip (111,350 bytes)
sortIndicator.png (167,832 bytes)   
sortIndicator.png (167,832 bytes)   

Dmitry Boyarintsev

2020-01-19 03:57

developer   ~0120529

Last edited: 2020-01-19 04:26

View 3 revisions

you need to provide a comparison event. (as shown on the wiki)
yet, that also mean, that you'll have to manage sortindicator manually, in the same manner, as SortDirection property

AutoSort is only capable of handling ssText properly. (in the sense, where the text should be sorted alphabetically)

Any complex sorting rules (i.e. autodetection of text data) is beyond the scope of TListView, and should be implemented as external (to TListView) code.

Chris Rorden

2020-01-19 13:25

reporter   ~0120545

Thanks for clarifying. I am closing this issue. Terrific job! I think this will help the whole community.

Issue History

Date Modified Username Field Change
2019-11-07 21:22 Chris Rorden New Issue
2019-11-07 21:22 Chris Rorden File Added: sort.png
2020-01-10 03:44 Dmitry Boyarintsev Assigned To => Dmitry Boyarintsev
2020-01-10 03:44 Dmitry Boyarintsev Status new => feedback
2020-01-10 03:44 Dmitry Boyarintsev LazTarget => -
2020-01-10 03:44 Dmitry Boyarintsev Note Added: 0120294
2020-01-12 01:13 Chris Rorden Note Added: 0120348
2020-01-12 01:13 Chris Rorden Status feedback => assigned
2020-01-17 02:50 Dmitry Boyarintsev Status assigned => resolved
2020-01-17 02:50 Dmitry Boyarintsev Resolution open => fixed
2020-01-17 02:50 Dmitry Boyarintsev Fixed in Revision => 62567
2020-01-17 02:50 Dmitry Boyarintsev Widgetset Cocoa => Cocoa
2020-01-17 02:50 Dmitry Boyarintsev Note Added: 0120490
2020-01-19 02:00 Chris Rorden File Added: SortData.zip
2020-01-19 02:00 Chris Rorden File Added: sortIndicator.png
2020-01-19 02:00 Chris Rorden Note Added: 0120527
2020-01-19 03:57 Dmitry Boyarintsev Note Added: 0120529
2020-01-19 03:58 Dmitry Boyarintsev Note Edited: 0120529 View Revisions
2020-01-19 04:26 Dmitry Boyarintsev Note Edited: 0120529 View Revisions
2020-01-19 13:25 Chris Rorden Note Added: 0120545
2020-01-19 13:26 Chris Rorden Status resolved => closed