DataTables comma on numbers

DataTables comma on numbers

gcla109gcla109 Posts: 3Questions: 2Answers: 0

Hello. I have a dataTable in a jsp page wherein I get data from the database. My problem is getting commas in the dataTables itself rather than have 00000000 continuously, it would be much better if it is 000,000,000. I have done this by using DecimalFormat in java. So now, I have commas on my number inputs in the dataTable.

The problem is they don't sort accordingly. For example I have
2,504
203,
1,251

When I sort, the 203 still remains in the middle rather than going in ascending or descending order. Please help thank you!

My table goes like this:
Columns: Location, Age Group, Both Count, Male Count, Female Count (of which the counts are the numbers with commas if reaching the thousands)

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 62,301Questions: 1Answers: 10,216 Site admin
    Answer ✓

    If you continue to return just a plain, unformatted number, you will then be able to use DataTables' built in number renderer.

    Allan

  • gcla109gcla109 Posts: 3Questions: 2Answers: 0

    I didn't know there was such a thing. Thank you so much! If it's not too much of a bother, would it be alright to ask where to put the code for the number renderer?

    If my code is like this;

    $("#error-ageGroup").DataTable({
            "paging": false,
            "ordering": true,
            "info": false,
            "fDom": false,
            "columns": [
                {"orderDataType": "dom-text", type: 'string'},
                {"orderDataType": "dom-text", type: 'string'},
                {"orderDataType": "dom-text", type: 'string'},
                {"orderDataType": "dom-text", type: 'string'},
                {"orderDataType": "dom-text", type: 'string'}
            ]
        });
    
  • allanallan Posts: 62,301Questions: 1Answers: 10,216 Site admin

    The documentation I linked to above gives an extensive overview of how to use the renderers and how to implement them in code. See also the columns.render reference documentation.

    I'm not sure how well they will work with the columns.orderDataType option. Do you have input elements in your table? If so, they aren't going to work well with renderer.

    Allan

This discussion has been closed.