$.fn.dataTable.render.number on row instead of column

$.fn.dataTable.render.number on row instead of column

BusterenBusteren Posts: 52Questions: 17Answers: 4

Hey, how can I get

$.fn.dataTable.render.number( ',', '.', 2, '$' )

on rows instead of columns?

Say initiating table like this

table= $('#table_ID').DataTable({
            columns: [
                { data: "1", render: $.fn.dataTable.render.number('', '.', 0, '', '$') },
                { data: "2", render: $.fn.dataTable.render.number('', '.', 0, '', '$') },
                { data: "3", render: $.fn.dataTable.render.number('', '.', 0, '', '$') },
                { data: "4", render: $.fn.dataTable.render.number('', '.', 0, '', '$') },
                { data: "5", render: $.fn.dataTable.render.number('', '.', 0, '', '$') }
            ]
        });

This question has an accepted answers - jump to answer

Answers

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

    Currently you can't. It is assumed that the data in a column is going to be of a like kind - i.e. a column of numbers, or a column of strings, etc.

    Can you show me a screenshot of the table you are trying to work with so I can understand what you are attempting to do?

    Thanks,
    Allan

  • BusterenBusteren Posts: 52Questions: 17Answers: 4
    edited August 2017

    Giving example through live.datatables.net
    Example of script: live.datatables.net/....
    I am also using the edtior just to note.
    The code html etc. It is the rows with text2, which I am trying to format with % sign after and then text3 row with a £ sign after. Cheers

  • allanallan Posts: 63,552Questions: 1Answers: 10,477 Site admin
    Answer ✓

    This is a table that has been pivoted is it? What you would need to do is have a custom renderer which would detect if the cell should be formatted a particular way based on its content. That isn't a feature that DataTables currently offers I'm afraid.

    Allan

  • BusterenBusteren Posts: 52Questions: 17Answers: 4

    Yes it is pivoted (just that the data sent from the server is pivoting it, so it get it as a normal data). Cheers, was just wondering if there were any prebuilt's as I wasn't sure how to do it without.

    Thanks T.

  • SoporteOpsSoporteOps Posts: 1Questions: 0Answers: 0

    Example too:
    { "targets": [6], render: $.fn.dataTable.render.number( ',', '.', 2, '' ) },

This discussion has been closed.