<!DOCTYPE html>
<html>
  <head>
    <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
    <link href="https://nightly.datatables.net/css/dataTables.dataTables.css" rel="stylesheet" type="text/css" />
    <script src="https://nightly.datatables.net/js/dataTables.js"></script>
    <meta charset=utf-8 />
    <title>DataTables - JS Bin</title>
  </head>
  <body>
    <div class="container">
      <table id="example" class="display nowrap" width="100%">
        <thead>
          <tr>
            <th>Length</th>
          </tr>
        </thead>
        <tfoot>
          <tr>
            <th>Length</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;
}
 
var data = [{"length":"29mm"},{"length":"30mm"},{"length":"30cm"},{"length":"29mm"},{"length":"45mm"},{"length":"50cm"},{"length":"25mm"},{"length":"5mm"},{"length":"7cm"},{"length":"9mm"},{"length":"10cm"},{"length":"21cm"},{"length":"22mm"},{"length":"29mm"},{"length":"31cm"}];
var table = new DataTable('#example', {
  data: data,
  columns: [
    {
      data: 'length',
      render: function (data, type, row) {
        if (type === 'sort' || type === 'type') {
          var multiplier = data.includes('cm') ? 10 : 1;
          data = data.replace(/[c|m]/g, '');
          return data * multiplier;
        }
        return data;
      }
    }
  ]
});
Output

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

Dismiss x
public
Bin info
anonymouspro
0viewers