Skip to content

Commit

Permalink
Merge pull request #3 from pavankataria/DefaultOrderingConfiguration
Browse files Browse the repository at this point in the history
Implements Default Ordering feature
+ Allows a default ordering feature
+ Configuration file allows you to specify options.
+ Adds default ordering options to configuration file allowing you to specify column index and order type.
  • Loading branch information
pavankataria authored Mar 11, 2017
2 parents c9435ae + 1675792 commit 9069c62
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 26 deletions.
4 changes: 2 additions & 2 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ PODS:
- Nimble
- Quick
- Quick (1.0.0)
- SwiftDataTables (0.2.5)
- SwiftDataTables (0.2.6)

DEPENDENCIES:
- FBSnapshotTestCase
Expand All @@ -30,7 +30,7 @@ SPEC CHECKSUMS:
Nimble: 415e3aa3267e7bc2c96b05fa814ddea7bb686a29
Nimble-Snapshots: e743439f26c2fa99d8f7e0d7c01c99bcb40aa6f2
Quick: 8024e4a47e6cc03a9d5245ef0948264fc6d27cff
SwiftDataTables: 05cf3879c95cb0dceb421bd7233e8f56602b1a18
SwiftDataTables: 83d1044c3a7f147dfd3a2e5e1370bc199f4f6441

PODFILE CHECKSUM: 9948d9c085c4f798f028aaa1e7597151e452280e

Expand Down
4 changes: 2 additions & 2 deletions Example/Pods/Local Podspecs/SwiftDataTables.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Example/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Example/SwiftDataTables/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@ class ViewController: UIViewController {

self.view.backgroundColor = UIColor.white

var options = DataTableConfiguration()
options.defaultOrdering = DataTableColumnOrder(index: 1, order: .ascending)


self.dataTable = SwiftDataTable(
data: self.data(),
headerTitles: self.columnHeaders()
headerTitles: self.columnHeaders(),
options: options
)

self.dataTable.backgroundColor = UIColor.init(red: 235/255, green: 235/255, blue: 235/255, alpha: 1)
Expand Down
2 changes: 1 addition & 1 deletion SwiftDataTables.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'SwiftDataTables'
s.version = '0.2.6'
s.version = '0.2.7'
s.summary = 'A Swift Data Table package that allows ordering, searching, and paging with extensible options.'

# This description is used to generate tags and improve search results.
Expand Down
18 changes: 14 additions & 4 deletions SwiftDataTables/Classes/DataTableConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,18 @@
import Foundation



struct DataTableConfiguration {

let shouldShowFooters: Bool
public struct DataTableColumnOrder {
//MARK: - Properties
let index: Int
let order: DataTableSortType
public init(index: Int, order: DataTableSortType){
self.index = index
self.order = order
}
}
public struct DataTableConfiguration {
public var defaultOrdering: DataTableColumnOrder? = nil
public init(){

}
}
43 changes: 30 additions & 13 deletions SwiftDataTables/Classes/SwiftDataTable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,13 @@ public class SwiftDataTable: UIView {
//MARK: - Lifecycle
public init(data: [[String]],
headerTitles: [String],
options: DataTableConfiguration = DataTableConfiguration(),
frame: CGRect = .zero)
{
// self.dataStructure = DataStructureModel(data: data, headerTitles: headerTitles)
super.init(frame: frame)

self.set(data: data, headerTitles: headerTitles)
self.set(data: data, headerTitles: headerTitles, options: options)

self.registerObservers()
}
Expand Down Expand Up @@ -128,24 +129,22 @@ public class SwiftDataTable: UIView {
collectionView.register(UINib(nibName: menuLengthIdentifier, bundle: podBundle), forSupplementaryViewOfKind: SupplementaryViewType.menuLengthHeader.rawValue, withReuseIdentifier: menuLengthIdentifier)
}

// public override var frame: CGRect {
// get {
// return super.frame
// }
// set {
// super.frame = frame
//// if frame != .zero {
//// self.calculateColumnWidths()
//// }
// }
// }
func set(data: [[String]], headerTitles: [String]){
func set(data: [[String]], headerTitles: [String], options: DataTableConfiguration? = nil){
self.dataStructure = DataStructureModel(data: data, headerTitles: headerTitles)
self.createDataCellViewModels(with: self.dataStructure)
self.layout = SwiftDataTableFlowLayout(dataTable: self)
self.calculateColumnWidths()
self.applyOptions(options)
}

func applyOptions(_ options: DataTableConfiguration?){
guard let options = options else {
return
}
if let defaultOrdering = options.defaultOrdering {
self.applyDefaultColumnOrder(defaultOrdering)
}
}
func calculateColumnWidths(){
//calculate the automatic widths for each column
self.columnWidths.removeAll()
Expand Down Expand Up @@ -330,6 +329,12 @@ extension SwiftDataTable {
self.reloadEverything()
}

fileprivate func applyDefaultColumnOrder(_ columnOrder: DataTableColumnOrder){
self.highlight(column: columnOrder.index)
self.applyColumnOrder(columnOrder)
self.sort(column: columnOrder.index, sort: self.headerViewModels[columnOrder.index].sortType)
}

func didTapColumn(index: IndexPath) {
defer {
self.update()
Expand Down Expand Up @@ -367,6 +372,18 @@ extension SwiftDataTable {
$0[column].highlighted = true
}
}

func applyColumnOrder(_ columnOrder: DataTableColumnOrder){
Array(0..<self.headerViewModels.count).forEach {
if columnOrder.index == $0 {
self.headerViewModels[$0].sortType = columnOrder.order
}
else {
self.headerViewModels[$0].sortType.toggleToDefault()
}
}
}


func toggleSortArrows(column: Int){
Array(0..<self.headerViewModels.count).forEach {
Expand Down

0 comments on commit 9069c62

Please sign in to comment.