pavankataria/SwiftDataTables

Catch the click in headers?

cgarcia55 opened this issue · 4 comments

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.

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)

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.

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?

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.