From 1920f41a841b6bae58e20cb0e1c075d4e3367da9 Mon Sep 17 00:00:00 2001 From: Pavan Kataria Date: Sat, 11 Mar 2017 19:19:51 +0000 Subject: [PATCH 1/4] Adds default ordering options --- Example/SwiftDataTables/ViewController.swift | 7 ++- .../Classes/DataTableConfiguration.swift | 10 +++-- SwiftDataTables/Classes/SwiftDataTable.swift | 43 +++++++++++++------ 3 files changed, 43 insertions(+), 17 deletions(-) diff --git a/Example/SwiftDataTables/ViewController.swift b/Example/SwiftDataTables/ViewController.swift index 40bf2f8..e8e921b 100644 --- a/Example/SwiftDataTables/ViewController.swift +++ b/Example/SwiftDataTables/ViewController.swift @@ -29,9 +29,14 @@ class ViewController: UIViewController { self.view.backgroundColor = UIColor.white + let options = DataTableConfiguration() + options.defaultOrdering = DataTableColumnOrder(1, .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) diff --git a/SwiftDataTables/Classes/DataTableConfiguration.swift b/SwiftDataTables/Classes/DataTableConfiguration.swift index 496f386..738c6a3 100644 --- a/SwiftDataTables/Classes/DataTableConfiguration.swift +++ b/SwiftDataTables/Classes/DataTableConfiguration.swift @@ -9,8 +9,12 @@ import Foundation - -struct DataTableConfiguration { +public struct DataTableColumnOrder { + let index: Int + let order: DataTableSortType +} +public struct DataTableConfiguration { - let shouldShowFooters: Bool +// let shouldShowFooters: Bool + var defaultOrdering: DataTableColumnOrder? = nil } diff --git a/SwiftDataTables/Classes/SwiftDataTable.swift b/SwiftDataTables/Classes/SwiftDataTable.swift index 2ff110a..46a3298 100644 --- a/SwiftDataTables/Classes/SwiftDataTable.swift +++ b/SwiftDataTables/Classes/SwiftDataTable.swift @@ -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() } @@ -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() @@ -330,6 +329,12 @@ extension SwiftDataTable { self.reloadEverything() } + private 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() @@ -367,6 +372,18 @@ extension SwiftDataTable { $0[column].highlighted = true } } + + func applyColumnOrder(_ columnOrder: DataTableColumnOrder){ + Array(0.. Date: Sat, 11 Mar 2017 19:27:44 +0000 Subject: [PATCH 2/4] Allows default ordering with correct access modifiers on structs --- Example/Podfile.lock | 4 ++-- .../Pods/Local Podspecs/SwiftDataTables.podspec.json | 4 ++-- Example/Pods/Manifest.lock | 4 ++-- .../Target Support Files/SwiftDataTables/Info.plist | 2 +- Example/SwiftDataTables/ViewController.swift | 4 ++-- SwiftDataTables/Classes/DataTableConfiguration.swift | 12 +++++++++--- SwiftDataTables/Classes/SwiftDataTable.swift | 2 +- 7 files changed, 19 insertions(+), 13 deletions(-) diff --git a/Example/Podfile.lock b/Example/Podfile.lock index 43402e2..0db48a7 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -12,7 +12,7 @@ PODS: - Nimble - Quick - Quick (1.0.0) - - SwiftDataTables (0.2.5) + - SwiftDataTables (0.2.6) DEPENDENCIES: - FBSnapshotTestCase @@ -30,7 +30,7 @@ SPEC CHECKSUMS: Nimble: 415e3aa3267e7bc2c96b05fa814ddea7bb686a29 Nimble-Snapshots: e743439f26c2fa99d8f7e0d7c01c99bcb40aa6f2 Quick: 8024e4a47e6cc03a9d5245ef0948264fc6d27cff - SwiftDataTables: 05cf3879c95cb0dceb421bd7233e8f56602b1a18 + SwiftDataTables: 83d1044c3a7f147dfd3a2e5e1370bc199f4f6441 PODFILE CHECKSUM: 9948d9c085c4f798f028aaa1e7597151e452280e diff --git a/Example/Pods/Local Podspecs/SwiftDataTables.podspec.json b/Example/Pods/Local Podspecs/SwiftDataTables.podspec.json index 2248f05..01cc197 100644 --- a/Example/Pods/Local Podspecs/SwiftDataTables.podspec.json +++ b/Example/Pods/Local Podspecs/SwiftDataTables.podspec.json @@ -1,6 +1,6 @@ { "name": "SwiftDataTables", - "version": "0.2.5", + "version": "0.2.6", "summary": "A Swift Data Table package that allows ordering, searching, and paging with extensible options.", "description": "SwiftDataTables allows you to display grid-like data sets in a nicely formatted table for iOS. The main goal for the end-user are to be able to obtain useful information from the table as quickly as possible with the following features: ordering, searching, and paging; where as for the developer is to allow for easy implementation with extensible options. This package was inspired by Javascript's DataTables package.", "homepage": "https://github.com/pavankataria/SwiftDataTables", @@ -13,7 +13,7 @@ }, "source": { "git": "https://github.com/pavankataria/SwiftDataTables.git", - "tag": "0.2.5" + "tag": "0.2.6" }, "platforms": { "ios": "9.0" diff --git a/Example/Pods/Manifest.lock b/Example/Pods/Manifest.lock index 43402e2..0db48a7 100644 --- a/Example/Pods/Manifest.lock +++ b/Example/Pods/Manifest.lock @@ -12,7 +12,7 @@ PODS: - Nimble - Quick - Quick (1.0.0) - - SwiftDataTables (0.2.5) + - SwiftDataTables (0.2.6) DEPENDENCIES: - FBSnapshotTestCase @@ -30,7 +30,7 @@ SPEC CHECKSUMS: Nimble: 415e3aa3267e7bc2c96b05fa814ddea7bb686a29 Nimble-Snapshots: e743439f26c2fa99d8f7e0d7c01c99bcb40aa6f2 Quick: 8024e4a47e6cc03a9d5245ef0948264fc6d27cff - SwiftDataTables: 05cf3879c95cb0dceb421bd7233e8f56602b1a18 + SwiftDataTables: 83d1044c3a7f147dfd3a2e5e1370bc199f4f6441 PODFILE CHECKSUM: 9948d9c085c4f798f028aaa1e7597151e452280e diff --git a/Example/Pods/Target Support Files/SwiftDataTables/Info.plist b/Example/Pods/Target Support Files/SwiftDataTables/Info.plist index c83163f..32648df 100644 --- a/Example/Pods/Target Support Files/SwiftDataTables/Info.plist +++ b/Example/Pods/Target Support Files/SwiftDataTables/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 0.2.5 + 0.2.6 CFBundleSignature ???? CFBundleVersion diff --git a/Example/SwiftDataTables/ViewController.swift b/Example/SwiftDataTables/ViewController.swift index e8e921b..288e7dd 100644 --- a/Example/SwiftDataTables/ViewController.swift +++ b/Example/SwiftDataTables/ViewController.swift @@ -29,8 +29,8 @@ class ViewController: UIViewController { self.view.backgroundColor = UIColor.white - let options = DataTableConfiguration() - options.defaultOrdering = DataTableColumnOrder(1, .ascending) + var options = DataTableConfiguration() + options.defaultOrdering = DataTableColumnOrder(index: 3, order: .descending) self.dataTable = SwiftDataTable( diff --git a/SwiftDataTables/Classes/DataTableConfiguration.swift b/SwiftDataTables/Classes/DataTableConfiguration.swift index 738c6a3..f6624c2 100644 --- a/SwiftDataTables/Classes/DataTableConfiguration.swift +++ b/SwiftDataTables/Classes/DataTableConfiguration.swift @@ -10,11 +10,17 @@ import Foundation 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 { - -// let shouldShowFooters: Bool - var defaultOrdering: DataTableColumnOrder? = nil + public var defaultOrdering: DataTableColumnOrder? = nil + public init(){ + + } } diff --git a/SwiftDataTables/Classes/SwiftDataTable.swift b/SwiftDataTables/Classes/SwiftDataTable.swift index 46a3298..ece15a8 100644 --- a/SwiftDataTables/Classes/SwiftDataTable.swift +++ b/SwiftDataTables/Classes/SwiftDataTable.swift @@ -329,7 +329,7 @@ extension SwiftDataTable { self.reloadEverything() } - private func applyDefaultColumnOrder(_ columnOrder: DataTableColumnOrder){ + fileprivate func applyDefaultColumnOrder(_ columnOrder: DataTableColumnOrder){ self.highlight(column: columnOrder.index) self.applyColumnOrder(columnOrder) self.sort(column: columnOrder.index, sort: self.headerViewModels[columnOrder.index].sortType) From d13dbec077099f3e4bbf545402e8e2943a7e0eba Mon Sep 17 00:00:00 2001 From: Pavan Kataria Date: Sat, 11 Mar 2017 19:33:04 +0000 Subject: [PATCH 3/4] Update demo project --- Example/SwiftDataTables/ViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Example/SwiftDataTables/ViewController.swift b/Example/SwiftDataTables/ViewController.swift index 288e7dd..59751c2 100644 --- a/Example/SwiftDataTables/ViewController.swift +++ b/Example/SwiftDataTables/ViewController.swift @@ -30,7 +30,7 @@ class ViewController: UIViewController { self.view.backgroundColor = UIColor.white var options = DataTableConfiguration() - options.defaultOrdering = DataTableColumnOrder(index: 3, order: .descending) + options.defaultOrdering = DataTableColumnOrder(index: 1, order: .ascending) self.dataTable = SwiftDataTable( From 167579264c4a6e3abb1cfe9ef51218c08978e996 Mon Sep 17 00:00:00 2001 From: Pavan Kataria Date: Sat, 11 Mar 2017 19:40:57 +0000 Subject: [PATCH 4/4] Updates podspec to 0.2.7 --- SwiftDataTables.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SwiftDataTables.podspec b/SwiftDataTables.podspec index 780daa9..f62badc 100644 --- a/SwiftDataTables.podspec +++ b/SwiftDataTables.podspec @@ -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.