<!DOCTYPE html>
<html>
  <head>
    
    
    <link href="https://cdn.datatables.net/1.10.11/css/jquery.dataTables.min.css" rel="stylesheet" type="text/css" />
    
    <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
    <link href="https://nightly.datatables.net/css/jquery.dataTables.css" rel="stylesheet" type="text/css" />
    
    <script src="https://nightly.datatables.net/js/jquery.dataTables.js"></script>
    
    
    <script src="https://cdn.datatables.net/buttons/1.1.2/js/dataTables.buttons.js"></script>
    
    <script src="https://cdn.datatables.net/buttons/1.1.2/js/buttons.html5.min.js"></script>
    
       
    
    <link href="https://cdn.datatables.net/buttons/1.1.2/css/buttons.dataTables.css" rel="stylesheet" type="text/css" />
    
    
    
    <meta charset=utf-8 />
    <title>DataTables - JS Bin</title>
  </head>
  
  
  
  <body>
    <div class="container">
     <table id="example" class="display" cellspacing="0" width="100%">
       
        <thead>
            <tr>
                <th>Name</th>
                <th>Position</th>
                <th>Office</th>
                <th>Extn.</th>
                <th>Start date</th>
                <th>Salary</th>
            </tr>
        </thead>
    </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;
}
 
var ajaxObj = {
    "data": [
        {
            "name": "Tiger Nixon",
            "position": "System Architect",
            "salary": "$320,800",
            "start_date": "2011\/04\/25",
            "office": "Edinburgh",
            "extn": "5421"
        },
        {
            "name": "Garrett Winters",
            "position": "Accountant",
            "salary": "$170,750",
            "start_date": "2011\/07\/25",
            "office": "Tokyo",
            "extn": "8422"
        },
        {
            "name": "Ashton Cox",
            "position": "Junior Technical Author",
            "salary": null,
            "start_date": "2009\/01\/12",
            "office": "San Francisco",
            "extn": "1562"
        },
        {
            "name": "Cedric Kelly",
            "position": "Senior Javascript Developer",
            "salary": "$433,060",
            "start_date": "2012\/03\/29",
            "office": null,
            "extn": "6224"
        },
        {
            "name": "Airi Satou",
            "position": null,
            "salary": "$162,700",
            "start_date": "2008\/11\/28",
            "office": "Tokyo",
            "extn": "5407"
        }
    ]
};
//String truncation function to add ellipsis
function truncate(inputString, length) {
    if (typeof (inputString) !== 'undefined') {
        if (inputString != null) {
            if (inputString.length > length)
                return inputString.substring(0, length) + '...';
            else
                return inputString;
        }
        else {
            return "";
        }
    }
    else {
        return "";
    }
}
$(document).ready(function() {
    $('#example').DataTable( {
      "aaData": ajaxObj.data,
//      ajax: '../../../../examples/ajax/data/objects.txt',
        "aoColumns": [
            { data: 'name' },
            { data: 'position' , render: function (data, type, row) {
                return type === 'export' ?
                    data : truncate(data, 10);
            }},
            { data: 'office' },
            { data: 'extn' },
            { data: 'start_date' },
            { data: 'salary' }
        ],
        dom: 'Bfrtip',
        buttons: [
            {
                extend: 'copyHtml5',
                exportOptions: { orthogonal: 'export' }
            },
            {
                extend: 'csvHtml5',
                exportOptions: { orthogonal: 'export' }
            }
        ]
    } );
} );
Output 300px

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

Dismiss x
public
Bin info
anonymouspro
0viewers