ADD non-numeric characters in numbers

ADD non-numeric characters in numbers

RockbRockb Posts: 97Questions: 0Answers: 0
edited June 2011 in Plug-ins
Hi Allan!

Here

http://www.datatables.net/plug-ins/sorting

I could find to avoid the "non-numeric" characters in numbers. But I'd like to have it vice-versa:

For example: "1000000" should be displayed as "1.000.000" and (of course) should be sortable, too.

Is there still a way and I couldn't get the line? If not, it would be great to add it to your to-do-list! :-)

Greetz from Berlin
Sebastian

Replies

  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin
    Hi Sebastian,

    Yes this is quite possible. You can populate your table with numbers and then have DataTables format it as you require with fnRender ( http://datatables.net/ref#fnRender ). You can also maintain the sorting by telling DataTables to use the original value rather than the rendered one with bUseRendered:false ( http://datatables.net/ref#bUseRendered ).

    Allan
  • RockbRockb Posts: 97Questions: 0Answers: 0
    Sorry, I don't get it...

    if I put this

    [code]"fnFormatNumber": function ( iIn ) {
    if ( iIn < 1000 ) {
    return iIn;
    } else {
    var
    s=(iIn+""),
    a=s.split(""), out="",
    iLen=s.length;

    for ( var i=0 ; i
  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin
    Did you use fnRender and bUserRendered as I suggested? Here is an example of fnRender in use: http://datatables.net/release-datatables/examples/advanced_init/column_render.html . You need to do your number formatting in fnRender.
  • RockbRockb Posts: 97Questions: 0Answers: 0
    Yes, I do already use the fnRender-Function to combine a Link (column no. "10") with the number (column no. "6"). The following is from the "aoColumns":

    [quote]{ "sName": "Number", "sTitle": "Number", "bSearchable": false, "fnRender": function ( oObj ) { return '' + oObj.aData[6] +''; }, "aTargets": [ 6 ], "sType": "num-html", "asSorting": [ "desc" ] },[/quote]

    And the number ("6") I'd like to format it like "1.000.000" or something like this. For sure not the link sourrounding it ;-)
  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin
    So you need to format the number in there: formatNumber(oObj.aData[6]) for example. You can reuse the DataTables fnFormatNumber function certainly, but that in it's "native" state is used for formatting the numbers that DataTables controls - like the information element for reporting the number of search results.

    Allan
  • RockbRockb Posts: 97Questions: 0Answers: 0
    edited June 2011
    Argh... it's not working... :-/

    I'have added this

    [code] "fnFormatNumber": function ( iIn ) {
    if ( iIn < 1000 ) {
    return iIn;
    } else {
    var
    s=(iIn+""),
    a=s.split(""), out="",
    iLen=s.length;

    for ( var i=0 ; i
  • RockbRockb Posts: 97Questions: 0Answers: 0
    edited July 2011
    It's still not working, what did I make wrong?

    The function:

    [code] "fnFormatNumber": function ( iIn ) {
    if ( iIn < 1000 ) {
    return iIn;
    } else {
    var
    s=(iIn+""),
    a=s.split(""), out="",
    iLen=s.length;

    for ( var i=0 ; i
  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin
    What is "formatNumber"? Have you defined that function somewhere? Are you getting a Javascript error on the console?

    Allan
  • RockbRockb Posts: 97Questions: 0Answers: 0
    ehm, you've described it here: http://datatables.net/forums/discussion/comment/22510#Comment_22510 I thought that's everything to do to add the points in the long numbers.
  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin
    That was an example function name. DataTables doesn't add any global functions to Javascript. You would need a function called "formatNumber" if you are going to call it! Is the Javascript console in your browser not giving an error?

    Allan
  • RockbRockb Posts: 97Questions: 0Answers: 0
    Sorry, Allan, actually I'm not quite familiar to JavaScript, php is my work. In JS I do the best practical way for me: try and error ;-D Okay, for sure, there is a need for this function. That makes sense.

    So HOW I do add this function and finally how to format the long numbers? I still don't get it.

    Sebastian
This discussion has been closed.