<!DOCTYPE html>
<html>
    <head>
        <link href="//datatables.net/download/build/nightly/jquery.dataTables.css" rel="stylesheet" type="text/css" />
  
        <script src="https://code.jquery.com/jquery-3.6.3.js"></script>
        <script src="//datatables.net/download/build/nightly/jquery.dataTables.js"></script>
        <meta charset=utf-8 />
        <title>DataTables - JS Bin</title>
    </head>
    <body>
        <div class="container">
            <table id="example" class="display" width="100%">
                <thead>
                    <tr>
                        <th>Name</th>
                        <th>Position</th>
                        <th>Office</th>
                        <th>Age</th>
                        <th>Start date</th>
                        <th>Salary</th>
                        <th>New Field</th>
                    </tr>
                </thead>
                <tfoot>
                    <tr>
                        <th>Name</th>
                        <th>Position</th>
                        <th>Office</th>
                        <th>Age</th>
                        <th>Start date</th>
                        <th>Salary</th>
                       <th>New Field</th>
                    </tr>
                </tfoot>
            </table>
        </div>
    </body>
</html>
 
body {
    font: 90%/1.45em "Helvetica Neue", HelveticaNeue, Verdana, Arial, Helvetica, sans-serif;
    margin: 0;
    padding: 0;
    color: #333;
    background-color: #fff;
}
i.exclamation:after {
  color: red;
  font-size: 20px;
  content: '\0021';
}
 
var dt = [];
var d = {};
d.name='My Name';
d.position = 'Up High';
d.office = 'No Where';
d.extn = '123';
d.start_date = 'Now';
d.salary = '$0';
dt.push(d);
console.log(d);
var table = new DataTable('#example', {
  ajax: '/ajax/objects.txt',
  columns: [
    {
      data: 'name',
      defaultContent: 'Just an example',
      render: function (d) {
        return undefined;
      }
    },
    { data: 'position' },
    { data: 'office' },
    { data: 'extn' },
    { data: 'start_date' },
    { data: 'salary' },
    { data: 'newField',
     defaultContent: 0,
     render: function ( data, type, full, meta )
     {
       if ( type === 'display') 
       {
         var rank = data
         /*
         if( data == undefined)
         {
           var rank = 0;
         }
        else
        {
          var rank = data;    
        }
        */
        if( rank == 0 )
        {
          rank = 'Meow';
        }
        else
        {
          rank = '<i class="red exclamation icon"></i>'
        }
        return rank;
      }
      return data;
     }
    },
  ],
});
2 errors 1 warning
Line 34: Missing semicolon.
Line 45: Use '===' to compare with '0'.
Line 51: Missing semicolon.
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers