diff --git a/CHANGELOG.md b/CHANGELOG.md
index f4e498d..d8ba84b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -18,7 +18,7 @@
## [0.2](https://github.com/pavankataria/SwiftDataTables/tree/0.2) (2017-03-10)
[Full Changelog](https://github.com/pavankataria/SwiftDataTables/compare/0.1.1...0.2)
-**Merged pull requests:**
+**Implemented enhancements:**
- Image bundle [\#1](https://github.com/pavankataria/SwiftDataTables/pull/1) ([pavankataria](https://github.com/pavankataria))
diff --git a/Example/CHANGELOG.md b/Example/CHANGELOG.md
new file mode 100644
index 0000000..1560569
--- /dev/null
+++ b/Example/CHANGELOG.md
@@ -0,0 +1,34 @@
+# Change Log
+
+## [0.2.6](https://github.com/pavankataria/SwiftDataTables/tree/0.2.6) (2017-03-11)
+[Full Changelog](https://github.com/pavankataria/SwiftDataTables/compare/0.2.5...0.2.6)
+
+## [0.2.5](https://github.com/pavankataria/SwiftDataTables/tree/0.2.5) (2017-03-10)
+[Full Changelog](https://github.com/pavankataria/SwiftDataTables/compare/0.2.4...0.2.5)
+
+## [0.2.4](https://github.com/pavankataria/SwiftDataTables/tree/0.2.4) (2017-03-10)
+[Full Changelog](https://github.com/pavankataria/SwiftDataTables/compare/0.2.3...0.2.4)
+
+## [0.2.3](https://github.com/pavankataria/SwiftDataTables/tree/0.2.3) (2017-03-10)
+[Full Changelog](https://github.com/pavankataria/SwiftDataTables/compare/0.2.2...0.2.3)
+
+## [0.2.2](https://github.com/pavankataria/SwiftDataTables/tree/0.2.2) (2017-03-10)
+[Full Changelog](https://github.com/pavankataria/SwiftDataTables/compare/0.2.1...0.2.2)
+
+## [0.2.1](https://github.com/pavankataria/SwiftDataTables/tree/0.2.1) (2017-03-10)
+[Full Changelog](https://github.com/pavankataria/SwiftDataTables/compare/0.2...0.2.1)
+
+## [0.2](https://github.com/pavankataria/SwiftDataTables/tree/0.2) (2017-03-10)
+[Full Changelog](https://github.com/pavankataria/SwiftDataTables/compare/0.1.1...0.2)
+
+**Implemented enhancements:**
+
+- Image bundle [\#1](https://github.com/pavankataria/SwiftDataTables/pull/1) ([pavankataria](https://github.com/pavankataria))
+
+## [0.1.1](https://github.com/pavankataria/SwiftDataTables/tree/0.1.1) (2017-03-09)
+[Full Changelog](https://github.com/pavankataria/SwiftDataTables/compare/0.1.0...0.1.1)
+
+## [0.1.0](https://github.com/pavankataria/SwiftDataTables/tree/0.1.0) (2017-03-09)
+
+
+\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
\ No newline at end of file
diff --git a/Example/Podfile.lock b/Example/Podfile.lock
index d012858..43402e2 100644
--- a/Example/Podfile.lock
+++ b/Example/Podfile.lock
@@ -12,7 +12,7 @@ PODS:
- Nimble
- Quick
- Quick (1.0.0)
- - SwiftDataTables (0.2.4)
+ - SwiftDataTables (0.2.5)
DEPENDENCIES:
- FBSnapshotTestCase
@@ -30,7 +30,7 @@ SPEC CHECKSUMS:
Nimble: 415e3aa3267e7bc2c96b05fa814ddea7bb686a29
Nimble-Snapshots: e743439f26c2fa99d8f7e0d7c01c99bcb40aa6f2
Quick: 8024e4a47e6cc03a9d5245ef0948264fc6d27cff
- SwiftDataTables: 3c87142d2539a9cd554e9567eb91689cfd9d6c39
+ SwiftDataTables: 05cf3879c95cb0dceb421bd7233e8f56602b1a18
PODFILE CHECKSUM: 9948d9c085c4f798f028aaa1e7597151e452280e
diff --git a/Example/Pods/Local Podspecs/SwiftDataTables.podspec.json b/Example/Pods/Local Podspecs/SwiftDataTables.podspec.json
index a0ac80b..2248f05 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.4",
+ "version": "0.2.5",
"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.4"
+ "tag": "0.2.5"
},
"platforms": {
"ios": "9.0"
diff --git a/Example/Pods/Manifest.lock b/Example/Pods/Manifest.lock
index d012858..43402e2 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.4)
+ - SwiftDataTables (0.2.5)
DEPENDENCIES:
- FBSnapshotTestCase
@@ -30,7 +30,7 @@ SPEC CHECKSUMS:
Nimble: 415e3aa3267e7bc2c96b05fa814ddea7bb686a29
Nimble-Snapshots: e743439f26c2fa99d8f7e0d7c01c99bcb40aa6f2
Quick: 8024e4a47e6cc03a9d5245ef0948264fc6d27cff
- SwiftDataTables: 3c87142d2539a9cd554e9567eb91689cfd9d6c39
+ SwiftDataTables: 05cf3879c95cb0dceb421bd7233e8f56602b1a18
PODFILE CHECKSUM: 9948d9c085c4f798f028aaa1e7597151e452280e
diff --git a/Example/Pods/Target Support Files/SwiftDataTables/Info.plist b/Example/Pods/Target Support Files/SwiftDataTables/Info.plist
index f7c6cd4..c83163f 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.4
+ 0.2.5
CFBundleSignature
????
CFBundleVersion
diff --git a/Example/SwiftDataTables.xcodeproj/project.pbxproj b/Example/SwiftDataTables.xcodeproj/project.pbxproj
index 3c56e7f..34e4eb8 100644
--- a/Example/SwiftDataTables.xcodeproj/project.pbxproj
+++ b/Example/SwiftDataTables.xcodeproj/project.pbxproj
@@ -510,7 +510,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
- TARGETED_DEVICE_FAMILY = 2;
+ TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
};
@@ -527,7 +527,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
- TARGETED_DEVICE_FAMILY = 2;
+ TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
};
diff --git a/Example/SwiftDataTables/Info.plist b/Example/SwiftDataTables/Info.plist
index eb18faa..81187dd 100644
--- a/Example/SwiftDataTables/Info.plist
+++ b/Example/SwiftDataTables/Info.plist
@@ -34,6 +34,15 @@
UIInterfaceOrientationPortrait
UIInterfaceOrientationLandscapeLeft
+ UIInterfaceOrientationPortraitUpsideDown
+ UIInterfaceOrientationLandscapeRight
+
+ UISupportedInterfaceOrientations~ipad
+
+ UIInterfaceOrientationPortrait
+ UIInterfaceOrientationLandscapeLeft
+ UIInterfaceOrientationPortraitUpsideDown
+ UIInterfaceOrientationLandscapeRight
diff --git a/Example/SwiftDataTables/ViewController.swift b/Example/SwiftDataTables/ViewController.swift
index 04993e9..40bf2f8 100644
--- a/Example/SwiftDataTables/ViewController.swift
+++ b/Example/SwiftDataTables/ViewController.swift
@@ -37,11 +37,8 @@ class ViewController: UIViewController {
self.dataTable.backgroundColor = UIColor.init(red: 235/255, green: 235/255, blue: 235/255, alpha: 1)
//25/255, green: 33/255, blue: 39/255, alpha: 1)
-
self.dataTable.autoresizingMask = [.flexibleWidth, .flexibleHeight]
-
self.dataTable.frame = self.view.bounds
-
self.view.addSubview(self.dataTable);
}
}
@@ -51,9 +48,9 @@ extension ViewController {
"Id",
"Name",
"Email",
- "Number",
- "City",
- "Balance"
+ "Number"
+// "City",
+// "Balance"
]
}
diff --git a/SwiftDataTables/Classes/DataStructureModel.swift b/SwiftDataTables/Classes/DataStructureModel.swift
index a20be28..c9ed688 100644
--- a/SwiftDataTables/Classes/DataStructureModel.swift
+++ b/SwiftDataTables/Classes/DataStructureModel.swift
@@ -43,8 +43,11 @@ public struct DataStructureModel {
self.headerTitles = headerTitles
let unfilteredData = data
let sanitisedData = unfilteredData.filter({ currentRowData in
- return currentRowData.count == self.columnCount
+ //Trim column count for current row to the number of headers present
+ let rowWithPreferredColumnCount = Array(currentRowData.prefix(upTo: self.columnCount))
+ return rowWithPreferredColumnCount.count == self.columnCount
})
+
self.data = sanitisedData//sanitisedData
self.shouldFitTitles = shouldMakeTitlesFitInColumn
self.columnAverageContentLength = self.processColumnDataAverages(data: self.data)
diff --git a/SwiftDataTables/Classes/SwiftDataTable.swift b/SwiftDataTables/Classes/SwiftDataTable.swift
index 2f8eca6..2ff110a 100644
--- a/SwiftDataTables/Classes/SwiftDataTable.swift
+++ b/SwiftDataTables/Classes/SwiftDataTable.swift
@@ -79,18 +79,19 @@ public class SwiftDataTable: UIView {
fileprivate var rowViewModels = [[DataCellViewModel]]()
fileprivate var paginationViewModel: PaginationHeaderViewModel!
fileprivate var menuLengthViewModel: MenuLengthHeaderViewModel!
-
+ fileprivate var columnWidths = [CGFloat]()
+
//MARK: - Lifecycle
public init(data: [[String]],
headerTitles: [String],
frame: CGRect = .zero)
{
- self.dataStructure = DataStructureModel(data: data, headerTitles: headerTitles)
+// self.dataStructure = DataStructureModel(data: data, headerTitles: headerTitles)
super.init(frame: frame)
- self.createDataCellViewModels(with: self.dataStructure)
- self.layout = SwiftDataTableFlowLayout(dataTable: self)
+
+ self.set(data: data, headerTitles: headerTitles)
+
self.registerObservers()
- self.collectionView.reloadData()
}
required public init?(coder aDecoder: NSCoder) {
@@ -127,11 +128,54 @@ 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]){
- let dataStructure = DataStructureModel(data: data, headerTitles: headerTitles)
- self.createDataModels(with:dataStructure)
+ self.dataStructure = DataStructureModel(data: data, headerTitles: headerTitles)
+ self.createDataCellViewModels(with: self.dataStructure)
+ self.layout = SwiftDataTableFlowLayout(dataTable: self)
+ self.calculateColumnWidths()
+ }
+
+ func calculateColumnWidths(){
+ //calculate the automatic widths for each column
+ self.columnWidths.removeAll()
+ for columnIndex in Array(0..= maxX){
- self.collectionView.contentOffset.x = maxX-1
+ self.collectionView.contentOffset.x = max(maxX-1, 0)
}
}
if self.disableScrollViewBottomBounce(){
@@ -353,6 +397,10 @@ extension SwiftDataTable {
return self.dataStructure.footerTitles.count
}
+
+ func shouldContentWidthScaleToFillFrame() -> Bool{
+ return true
+ }
func shouldSectionHeadersFloat() -> Bool {
return true
}
@@ -381,13 +429,39 @@ extension SwiftDataTable {
return 0
}
- func widthForColumn(index: Int) -> CGFloat {
- let dataStructure = self.dataStructure
+
+ /// Automatically calcualtes the width the column should be based on the content
+ /// in the rows under the column.
+ ///
+ /// - Parameter index: The column index
+ /// - Returns: The automatic width of the column irrespective of the Data Grid frame width
+ func automaticWidthForColumn(index: Int) -> CGFloat {
+ print(self.frame.width)
let columnAverage: CGFloat = CGFloat(dataStructure.averageDataLengthForColumn(index: index))
let sortingArrowVisualElementWidth: CGFloat = 20 // This is ugly
let averageDataColumnWidth: CGFloat = columnAverage * self.pixelsPerCharacter() + sortingArrowVisualElementWidth
return max(averageDataColumnWidth, max(self.minimumColumnWidth(), self.minimumHeaderColumnWidth(index: index)))
}
+// func automaticWidthForAllColumns(){
+// let automaticCalculatedWidth: CGFloat = Array(0.. CGFloat {
+ return self.columnWidths[index]
+ }
+
+ func calculateContentWidth() -> CGFloat {
+ return Array(0.. CGFloat {
return 44
@@ -400,6 +474,7 @@ extension SwiftDataTable {
func minimumColumnWidth() -> CGFloat {
return 70
}
+
func minimumHeaderColumnWidth(index: Int) -> CGFloat {
return CGFloat(self.pixelsPerCharacter() * CGFloat(self.dataStructure.headerTitles[index].characters.count))
}
diff --git a/SwiftDataTables/Classes/SwiftDataTableFlowLayout.swift b/SwiftDataTables/Classes/SwiftDataTableFlowLayout.swift
index a0bf7a1..75a3392 100644
--- a/SwiftDataTables/Classes/SwiftDataTableFlowLayout.swift
+++ b/SwiftDataTables/Classes/SwiftDataTableFlowLayout.swift
@@ -37,7 +37,7 @@ class SwiftDataTableFlowLayout: UICollectionViewFlowLayout {
guard self.cache.isEmpty else {
return
}
-
+ self.dataTable.calculateColumnWidths()
let methodStart = Date()
var xOffsets = [CGFloat]()
@@ -91,7 +91,7 @@ class SwiftDataTableFlowLayout: UICollectionViewFlowLayout {
}
override var collectionViewContentSize: CGSize {
- let width = Array(0..