Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: formatting #121

Closed

Conversation

jayden-arrai
Copy link

Created a way to format cells. Added default formatting types of
boolean, currency, date, number, and time. Created a demo with multiple
formats used and added documentation for the feature.

Created a way to format cells.  Added default formatting types of
boolean, currency, date, number, and time.  Created a demo with multiple
formats used and added documentation for the feature.
@warpech
Copy link
Member

warpech commented Sep 9, 2012

Thanks @jayden-emergence . This is definitely useful and clever.

I just have some questions. Why did you decide to format the values in "beforedatachange.handsontable"? I think that text formatting is only part of the presentation and could be applied in setDataAtCell (just before line td.innerHTML = value.replace(/\n/g, '<br/>');). Won't you agree?

@jayden-arrai
Copy link
Author

I decided to do it this way for a couple reasons. Firstly I didn't have time to figure out the best way. And secondly I did some testing in excel 2007 to see what it does.

If you type in excel the following:
2.33333
1.2345

Format the first cell to Number with 2 decimal places and the second cell to currency you will then see the following:
2.33
$1.23

If you copy this and paste it into something else you get the same results as what you see above.

Also I tried saving the file in a number of formats (.csv, .html, .pdf, .txt, .prn, .dif) and you also get the same results as what you see. I only found one save format (that isn't compressed in some way) that has the unformatted numbers. (XML Spreadsheet 2003)

So because of that I thought the data sent to the user when you are trying to save should be the formatted versions.

If you can think of a better way of doing this by all means go ahead. Hopefully some of my code is reusable.

@valerianrossigneux
Copy link

I mostly agree with @warpech, it should only be applied to the presentation, though I can see usecases for what you're describing.

Do you plan to merge this (modified or not) soon? This is exactly what I need I think :) (issue/question #137)

@warpech
Copy link
Member

warpech commented Sep 19, 2012

This will be a little bit altered and merged in next 2 weeks. I cannot give you the exact date, but I am trying my best :)

This was referenced Sep 19, 2012
@josegrad
Copy link

josegrad commented Oct 2, 2012

Hi, I was just now checking a way to add milliard separators to numbers in my tables.
The idea is that when the users enter 1234,5 it would automatically transform it into 1,234.5

The international standard is using , (comma) milliard separator and . (point) for decimals. Though many countries use it the other way around. So the formatting should be based on locale anyway.

But I think this change would be mechanism to achieve this automatic conversion, right?

Based on warpech it could be available soon I believe.

Cheers.

@jayden-arrai
Copy link
Author

The code I wrote for the formatting will not do this. I've never really needed to deal with internationalized numbers (here in Canada) before so I wrote enough to at least handle a comma being used for the decimal symbol. There is probably better code for formatting numbers and currency out there somewhere. I just did the best I could for what was needed by a project.

@josegrad
Copy link

josegrad commented Oct 2, 2012

Oh, I thought it would automatically add milliard and decimal separators based on some predefined rules.
If so those rules could be changed based on the user's locale for example.

warpech added a commit that referenced this pull request Feb 27, 2013
@warpech
Copy link
Member

warpech commented Feb 27, 2013

I feel sorry for not merging this pull request long time ago, but it seemed that it may be hard to maintain in future. I was looking for a solution where a custom cell types could use external libraries for data formatting and UI controls.

Today one of such things was released in version 0.8.6 - "numeric" cell type. It allows to keep a cell value as number JavaScript type and present it as formatted number or currency.

More about this new cell type here: http://handsontable.com/demo/numeric.html

@warpech
Copy link
Member

warpech commented Mar 26, 2013

Now, when we have numeric and date cell types build in in Handsontable (v0.8.9+), I think this pull request can be closed.

Sorry that I could not merge it, but I opted for a solution that is using external libraries.

Anyway, you influenced the changes a lot, thanks a lot @jayden-emergence!

@warpech warpech closed this Mar 26, 2013
budnix pushed a commit that referenced this pull request Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants