pavankataria / SwiftDataTables

A Swift Data Table package, display grid-like data sets in a nicely formatted table for iOS. Subclassing UICollectionView that allows ordering, and searching with extensible options.
MIT License
448 stars 69 forks source link

Delegate method for row color: changes Columns instead of Rows! #50

Closed PerplexedFox closed 4 years ago

PerplexedFox commented 4 years ago

Hi,

I need a way to fixedly highlight one row (depending on data, do that after sorting the right row is still highlighted) So I implemented the delegate functions

 func dataTable(_ dataTable: SwiftDataTable, highlightedColorForRowIndex at: Int) -> UIColor

and

func dataTable(_ dataTable: SwiftDataTable, unhighlightedColorForRowIndex at: Int) -> UIColor}

however, instead of alternating rows (horizontally), these methods color the whole columns!

Can you fix it?

pavankataria commented 4 years ago

Hi, the API currently does not support resizing a column automatically based on the width of its content as it is out of the original scope. My hope is to be able to figure out the best way to do this.

Until then you'll have to decide what width you'd like for your columns and specify the width by opting out of automatic width calculation and using the widthForColumnAt delegate method.

PerplexedFox commented 4 years ago

Hi, thank you for the answer. The biggest issue I have is that this resizing works seemingly at random so that many headers are cropped, while others made very wide. Do you have any idea why the cropping occurs?

Screenshot 2020-04-02 at 19 30 34 Screenshot 2020-04-02 at 19 30 19 Screenshot 2020-04-02 at 19 32 20
pavankataria commented 4 years ago

You've already raised this in a new issue which is the correct way to go about this. We can leave this issue open for the colouring issue.

You mentioned highlighting rows after sorting, could you please explain what you expect in regards to your row colouring?

pavankataria commented 4 years ago

Screenshot 2020-04-05 at 13 06 27 Rows are colouring as expected. If you have a different expectation please outline how you'd like to interface with the library and what coloring feature you would like to see.

PerplexedFox commented 4 years ago

Hi, thanks for your answer.

Since I may not share my project, I created a new one with two view Controllers but the same data. You can find it here: https://github.com/PerplexedFox/SwiftDataTables_minEx

You will find the example of the color delegate function problem(func dataTable(_ dataTable: SwiftDataTable, unhighlightedColorForRowIndex at: Int) -> UIColor and func dataTable(_ dataTable: SwiftDataTable, highlightedColorForRowIndex at: Int) -> UIColor) I described above

for the following code

Screenshot 2020-04-14 at 12 28 52

this is the result

Screenshot 2020-04-14 at 12 28 45
PerplexedFox commented 4 years ago

Got it.

in

public func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
        let cellViewModel = self.rowModel(at: indexPath)

        if cellViewModel.highlighted {
            cell.contentView.backgroundColor = delegate?.dataTable?(self, highlightedColorForRowIndex: indexPath.item) ?? self.options.highlightedAlternatingRowColors[indexPath.section % self.options.highlightedAlternatingRowColors.count]
        }
        else {
            cell.contentView.backgroundColor = delegate?.dataTable?(self, unhighlightedColorForRowIndex: indexPath.item) ?? self.options.unhighlightedAlternatingRowColors[indexPath.section % self.options.unhighlightedAlternatingRowColors.count]
        }

indexPath.item must be replaced by indexPath.section