Wijmo Number Formatting

Originally Posted 18 September 2012, 8:10 pm EST

  • Originally Posted 18 September 2012, 8:10 pm EST

    Now I've got another question, ha! (only thought you'd avoided me today, I bet you did!)

    ::coughs::Anyway... I have a column in the grid I'm working in that is just suppose to be a number with no formatting. I've looked over https://github.com/jquery/globalize#numbers and Googled a bit, but can't seem to find this answer...

    What I want to see is just

    12345

    not

    12,345

    What's the right dataFormatString for this? Currently I have

    dataType: "number", dataFormatString: "n0"

    As I want no decimals too, but have found no hints beyond that.
  • Reply

    Dear all,

    Well, I've decided I want my cake and eat it too! When I enabled filtering on the table with the 'D' format, the filter has decimal places in it. I did a bit of research, and I understand that it's because the Wijmo inputs don't read in the JQuery globalization like the grid does, BUT that ya'll were able to account for the 'n0' format when it came to filters (IE - If the dataFormatString = 'n0', the filter has no decimals). I've modified the last example we had to show filtering, and you can see that column GP (which I've now formatted as a number with 'n0') shows no decimal points in the filter field, but column Numbers does have them.

    Basically, the upshot is: Is there a workaround that ya'll can offer me, or can you direct me to the place in the Wijmo JS files where I can go poke it until fix (or broken, hehe). Any suggestions would be appreciated!

    BTW - You guys do a great job, keep up the hard work!
    2012/10/Wijmo-UnformatterNumbers.html
  • Reply

    Hello Amanda,

    You can set the dataFormatString to 'D' to get the desired behavior. I have modified your sample and numbers are now sorted in proper way.

    Regards
    2012/09/Wijmo-UnformatterNumbers.html
  • Reply

    Hello Ashish!

    Thanks for the reply!

    My issue with leaving them unformatted as you suggested is that leaves them as a string, which means when they get sorted, its AS a string, not as a number. In my expansion of your lovely example that I've attached, you can see that this means that all the numbers starting with '1' are grouped, then '2', then '3', etc, without regard to the actual numerical order of the numbers. This field is a numerical primary key field that is expected to be sorted as a number that we simply wish to leave unformatted.
    2012/09/Wijmo-Example.html
  • Reply

    Hello Amanda,

    If you do not want any formatting then I would suggest not to set any dataFormatString.

    Kindly check the attached sample implementing the same.

    Regards
    2012/09/Wijgrid_Numbers.html
  • Reply

    Oh, Thank you Ashish! :D That's exactly what I wanted!! <3

    BTW - Is there somewhere obvious that I've missed that explains what dataFormatString takes and what the formats look like? In my explorations, I've not seen the 'D' mentioned.

    Again, thank you for your time! You've saved me a bit of headache!
  • Reply

    I've read the linked discussion, but in my experience, most solutions to difficulties with javascript libraries that involve 'setTimeout' are prone to causing more problems further down the road because they cause inconsistent and non-repeatable behaviour that relies on arbitrary timings. Typically, if 'setTimeout' solutions are the ONLY way to achieve a behaviour, it's a pretty good indication that the library in question has a flaw in it.

    From the look of this conversation, the number formatting in the wijmo grid was not very well thought-out, since the default behaviour is to add decimal points. I would be surprised if you would try to convince me that default behaviour is what most users would want. I also doubt that most users would want a '0' sitting in each of the filter boxes for numeric columns. While I appreciate taking the time to find work-arounds for users, it would also be helpful to users to acknowledge the shortcomings of the feature and offer some indication of if this will be improved in future versions.

    Thanks.
  • Reply

    Hello Amanda,

    I have modified your sample and now, there is no decimal point in the filter input textbox of the last column having dataFormatString as 'D'.

    Let me know if I misunderstood your query.

    Regards
    2012/10/Wijmo-UnformatterNumbers1.html
  • Reply

    Ashish,

    That's what I was looking for! It does reset when the column is sorted, but I can poke it and see if I can figure out how to keep the formatting no matter. Thanks!
  • Reply

    This improves things a lot, but we're still stuck with that ugly "0" in the filter text box. The only way I can think of to add some code that manually removes the "0" after the grid initializes.
    I hope all of this behaviour can somehow get rolled into the next version of Wijmo. In my development domain, I'm almost never working with decimal numbers. Unfortunately, presenting them as strings isn't an option for me, even besides the sorting problem: if you don't properly indicate that the column is a number in the wijmo grid it breaks the filtering support with the BreezeDataView. The filter values will get surrounded by quotes in the query string, which causes Breeze/WebApi-OData to reject the query as invalid (comparing a string to an integer).
  • Reply

    Hello,

    I do understand your point and have forwarded it to the development team as enhancement request. Hopefully, in future versions, we would have an option to display default values or not.

    Regards
  • Reply

    Hello,

    You can refer to the following link discussing the same thing i.e. how to remove default value from filter box:
    http://wijmo.com/topic/default-0-value-in-filter/

    Regards
  • Reply

    Hi

    Unable to access the links in previous posts, can you update how to do the same in latest version of wijmo grid.

    Needed 12345

    not

    12,345

    <wj-flex-grid-column cssClass="text-left" [header]="'ID'"
    [binding]="'Id'" width="*" [wordWrap]="true">
    </wj-flex-grid-column>
  • Reply

    I would like to see an answer for this in the latest version as well. Being able to use a format string as in other versions of the grid would be the desired method. I.e.


    <wj-flex-grid-column header="Numbers #"
    binding="numberProp"
    format-string="0"></wj-flex-grid-column>


    And the format string should work as in excel....
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels