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

Catch the click in headers? #45

Open cgarcia55 opened 4 years ago

cgarcia55 commented 4 years ago

it is possible to intercept the didTapColumn function, in order to manipulate the sortof the information, since I have a problem in which I cannot format the numbers (example: $ 1,234,344.44) since they are converted to string and when accommodating them it does not correctly.

pavankataria commented 4 years ago

I'm not sure I understand. What is the connection between the didTapColumn and formatting numbers? You should be able to format the numbers as you please and then insert that into the Data object as a string.

For example

numberFormatter.style = .currency
numberFormatter.locale = "en_GB"
let number = NSDecimalNumber(decimal: 1234344.44)
numberFormatter.string(from: number)
cgarcia55 commented 4 years ago

An apology if I did not explain myself well, I have already formatted the data, the detail is that if I press the header of any of the columns, the sort that gives me is incorrect because the value of the data is not double, rather its a string ( or so I think that is the reason), since it does not give me a completely correct ascending arrangement neither descending one . I attach an image.

table

That is why I tried to catch the click on the header (assuming it was the didtapColumn) and this be able to do the sort by myself.

I hope I explained myself well. Thanks in advance and greetings.

pavankataria commented 4 years ago

Okay, that's a problem. Thank you for writing such a detailed and helpful response. What we need is a custom sort allowing you to define the sort order for specific columns.

I will want to work on this as soon as possible. Can you tell me how you would want to define the sorting behavior yourself?

cgarcia55 commented 4 years ago

I had the idea of managing a kind of absolute value by converting the currency value to double, in order to make a normal ascending arrangement. That was why my question, if it was possible to intercept the click in the header. to sort from the arrangement that fills the table.