DAArrayDataSource

Overview

DAArrayDataSource is an unsupported helper class that makes it easy to render data from a NSArray of KVO-compliant objects (such as rows from a DADataTable in a NSTableView component. It provides the following functionality:

  • NSTableViewDataSource methods for filling the view
  • Support for inline editing (toggle-able via the readonly property)
  • Two-way sorting of data in the table view by clicking the header
  • Grid coloring per row, via delegate callbacks
  • Automatic highlighting of changed rows with bold font, when showing DADataTableRows
  • Automatic adjustment of row-height for the value of a chosen field
  • Persistence of selection when reloading and sorting data

While most advanced data entry applications will require custom data sources or Cocoa Binding, DAArrayDataSource provides a convenient and easy way to "just get some data up" in a grid – whether that data comes from a DADataTable or another KVC compliant source.

Location


 

array  retain

Represents the array of the DADataTableRow to show in NSTableView. (Re)assigning this property will automatically update the view, as needed.

@property (retain) NSArray *array

delegate  assign

Delegates implementing the DAArrayDataSourceDelegate protocol, to be called for advanced features, such as row coloring or handling double clicks.

@property (assign) id<DAArrayDataSourceDelegate> delegate

fontSize  assign

Specifies the font size for text in the NSTableView rows.

@property (assign) CGFloat fontSize

mainTextField  copy

Identifies a field (or KVC name) that will be considered the main "text" of the table. When set, each row will automatically be sized to the appropriate height so that this text is fully visible. This property is useful for tables with one text field and additional auxiliary fields.

@property (copy) NSString *mainTextField

maxMainTextFieldHeight  assign nonatomic

Specifies MAX height for each row in the NSTableView.

@property (assign, nonatomic) int maxMainTextFieldHeight

readonly  assign

Defines whether the NSTableView will allow inline editing (YES) by double-clicking on fields, or not (NO). If set to YES, the array elements must be KVC-compliant for updating.

@property (assign) BOOL readonly

rowHeight  assign

Specifies the height of rows in NSTableView.

@property (assign) CGFloat rowHeight

secondarySortField  nonatomic retain

Contains the name of the second field is used to sort the data. For example if your sortField is "City" and secondarySortField is "LastName" then data in the data source will be sorted by City then by LastName

@property (nonatomic, retain) NSString *secondarySortField

selectedRow

Represent the instance of the first selected row. If nothing selected then it returns nil.

@property (readonly) id selectedRow

selectedRowCount

Returns the count of selected rows.

@property (readonly) NSInteger selectedRowCount

selectedRows

Represent array of selected rows. If no one row selected then it returns an empty array

@property (readonly) NSArray *selectedRows

selectRow:

Method takes row instance and select it in the managed table view. If table view does not contain given row then method does nothing.

- (void) selectRow:(id)object

Parameters:

  • object: instance of the DADataTableRow to select

sortAscending  assign nonatomic

Boolean flag that defines order of sorting data. YES means accending and NO means descending sort order.

@property (assign, nonatomic) BOOL sortAscending

sortField  nonatomic retain

Contains the name of the table field which should be used to sort the data.

@property (nonatomic, retain) NSString *sortField

sortLocalizedCaseInsensitive  assign nonatomic

Boolean flag that managing applying localized and case insensetive comparison for sorting the data.

@property (assign, nonatomic) BOOL sortLocalizedCaseInsensitive

tableView  assign

Reference to NSTableView outlet which is used for representing data

@property (assign) NSTableView *tableView

 

array  retain

Represents the array of the DADataTableRow to show in NSTableView. (Re)assigning this property will automatically update the view, as needed.

@property (retain) NSArray *array

delegate  assign

Delegates implementing the DAArrayDataSourceDelegate protocol, to be called for advanced features, such as row coloring or handling double clicks.

@property (assign) id<DAArrayDataSourceDelegate> delegate

fontSize  assign

Specifies the font size for text in the NSTableView rows.

@property (assign) CGFloat fontSize

mainTextField  copy

Identifies a field (or KVC name) that will be considered the main "text" of the table. When set, each row will automatically be sized to the appropriate height so that this text is fully visible. This property is useful for tables with one text field and additional auxiliary fields.

@property (copy) NSString *mainTextField

maxMainTextFieldHeight  assign nonatomic

Specifies MAX height for each row in the NSTableView.

@property (assign, nonatomic) int maxMainTextFieldHeight

readonly  assign

Defines whether the NSTableView will allow inline editing (YES) by double-clicking on fields, or not (NO). If set to YES, the array elements must be KVC-compliant for updating.

@property (assign) BOOL readonly

rowHeight  assign

Specifies the height of rows in NSTableView.

@property (assign) CGFloat rowHeight

secondarySortField  nonatomic retain

Contains the name of the second field is used to sort the data. For example if your sortField is "City" and secondarySortField is "LastName" then data in the data source will be sorted by City then by LastName

@property (nonatomic, retain) NSString *secondarySortField

selectedRow

Represent the instance of the first selected row. If nothing selected then it returns nil.

@property (readonly) id selectedRow

selectedRowCount

Returns the count of selected rows.

@property (readonly) NSInteger selectedRowCount

selectedRows

Represent array of selected rows. If no one row selected then it returns an empty array

@property (readonly) NSArray *selectedRows

sortAscending  assign nonatomic

Boolean flag that defines order of sorting data. YES means accending and NO means descending sort order.

@property (assign, nonatomic) BOOL sortAscending

sortField  nonatomic retain

Contains the name of the table field which should be used to sort the data.

@property (nonatomic, retain) NSString *sortField

sortLocalizedCaseInsensitive  assign nonatomic

Boolean flag that managing applying localized and case insensetive comparison for sorting the data.

@property (assign, nonatomic) BOOL sortLocalizedCaseInsensitive

tableView  assign

Reference to NSTableView outlet which is used for representing data

@property (assign) NSTableView *tableView

 

selectRow:

Method takes row instance and select it in the managed table view. If table view does not contain given row then method does nothing.

- (void) selectRow:(id)object

Parameters:

  • object: instance of the DADataTableRow to select

 

  • Using DAArrayDataSource (Article)