Numbers and Currency not being detected

Numbers and Currency not being detected

eoinriggseoinriggs Posts: 4Questions: 1Answers: 0

I have some number and currency columns in my HTML table.

I can not get DataTables to identify as a number and right-aling the column and standardize the decimal places.

For example I have '1.1' showing left aligned, rather than $1.10 right aligned.

Thanks

Answers

  • allanallan Posts: 63,552Questions: 1Answers: 10,476 Site admin

    Can you link to the page showing the issue please so I can help to debug it.

    Allan

  • eoinriggseoinriggs Posts: 4Questions: 1Answers: 0

    H Allan

    I have put a link up with a couple of rows of data. I want all the number columns to display as numbers, right aligned with 2 decimals.

    http://live.datatables.net/munoveni/1

    Thanks

  • allanallan Posts: 63,552Questions: 1Answers: 10,476 Site admin

    DataTables has a number of built in classes in its stylesheet which you can use to align column text.

    To get your numbers formatted as you want, use the number formatter.

    Allan

  • eoinriggseoinriggs Posts: 4Questions: 1Answers: 0

    Hi Allan

    Thanks for the message, much appreciated.

    I tried adding the number formatter, but I cannot get it working.

    Could you show me an example of how to use it?

  • kthorngrenkthorngren Posts: 21,353Questions: 26Answers: 4,955

    Can you build a test case showing what you've tried and someone can help fix it?

    Kevin

  • eoinriggseoinriggs Posts: 4Questions: 1Answers: 0

    Thanks kthrongren.

    I have updated my example adding the number formatter, but it does not work. I am clearly missing something obvious.

    live.datatables.net/fegohote/1/

    Thanks

  • kthorngrenkthorngren Posts: 21,353Questions: 26Answers: 4,955
    edited October 2017

    Good, thanks. I've updated your test case:
    http://live.datatables.net/qahoyusu/1/edit

    The number formatter example Allan linked to is just a snippet of a full config using columns.data. Since you are not using this option then columnDefs needs to be used to define the target column (5) and the renderer.

    This also needs to be placed inside the Datatables function. Notice the code is within a new set of {}.

    var table = $('#table_SQL').DataTable({
       //init code here
     });                                 
    

    Hope this helps.

    Kevin

  • eoinriggseoinriggs Posts: 4Questions: 1Answers: 0

    Thanks Kevin, that works great.

This discussion has been closed.