Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8812849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:41:56+00:00 2026-06-14T03:41:56+00:00

I have a datatable with 4 columns that hold currency. Currently I’m treating them

  • 0

I have a datatable with 4 columns that hold currency. Currently I’m treating them as normal columns and manually appending ‘$’ to each value. Now I need to format the column to have commas as well. Is there any plug-in to do this? I also want to remove the manual addition of ‘$’ value. I checked few sites, but I really didn’t understand how they work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T03:41:57+00:00Added an answer on June 14, 2026 at 3:41 am

    [Updating answer to use DataTables 1.9+ and to honor rynop’s better answer. Original answer preserved below the horizontal rule, but it’s both out of date and less efficient than it should be.]

    Since it is really the data that you want to modify, not the entire cell, you should be using the “render” property inside of the columns definition. To produce clean code, you could store the actual modification method elsewhere and just call over to it:

    var myTable = $('#mytable').DataTable({
      ...
      "columns": [
        { 
          "data" : "key_of_column",
          "render" : function( data, type, full ) {
            // you could prepend a dollar sign before returning, or do it
            // in the formatNumber method itself
            return formatNumber(data);                          
          }
        }
      ]
      ...
    });
    
    // elsewhere... probably more likely in a utility namespace or module
    function formatNumber(n) {
      return n.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
    }
    

    formatNumber uses the regex from this accepted answer:

    Add comma to numbers every three digits


    [original answer]

    I wouldn’t add dollar values to each cell myself, a decision that has the side-effect of reducing the complexity of what you need to do. 😉 In any spreadsheet or table of currency values, you only need to put the currency symbol in the header or the first row. Putting it in the header will make your life easier, putting it in the first row will actually add complexity to your problem.

    So, back to DataTables itself, you have multiple ways to skin this cat but here are two:

    1. Render the whole table without the commas (ie. default DataTables behaviour) but adding a class to those particular cells with the sClass parameter. Then use fnDrawCallback to fire the comma-creating function as described in the above link.

    2. Use only the regex from the above link to modify the cell as data comes in.

    Something like this (where 3 is the zero-index column that you’re modifying):

    "aoColumnDefs": [ {
       "aTargets": [3],
       "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
         var $currencyCell = $(nTd);
         var commaValue = $currencyCell.text().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
         $currencyCell.text(commaValue);
       }
    }]
    

    (aoColumnDefs is part of your initialization object passed to dataTable());

    If you absolutely MUST add the dollar sign, you would just prepend it in the same function before the text function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one datatable. In that table I have columns named [Total Day], [Present
Lets say you have a DataTable that has columns of id, cost, qty: DataTable
I have a datatable with 4 columns A, B, C and D such that
I have a datatable with three columns Id name value value1 I want to
I have a DataTable with 3 columns (a,b,c) and a docx file with the
I have a datatable with two columns, Column 1 = EmpID Column 2 =
I'm using Visual Studio 2005 and have a DataTable with two columns and some
I have a Datatable with Id(guid) and Name(string) columns. I traverse through the data
Background: I have a jQuery Datatable with 53x columns. The first column is the
Let's say I have a DataTable: DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn(Country, typeof(string)));

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.