Sha256: 018e0b767a6aa78005219fa81c32563064d4f58b32c39ef4b12039cf546a077a

Contents?: true

Size: 1.69 KB

Versions: 4

Compression:

Stored size: 1.69 KB

Contents

$(document).ready(function(){
  if(!sortPlease) return;
  $.tablesorter.addWidget({
    id: "columnHighlight",
    format: function(table) {
      if (!this.tds)
        this.tds =  $("td", table.tBodies[0]);
      if (!this.headers)
        this.headers = $("thead th", table);
      this.tds.removeClass("sorted");
      var ascSort = $("th." + table.config.cssAsc);
      var descSort = $("th." + table.config.cssDesc);
      if (ascSort.length)
        index = this.headers.index(ascSort[0]);
      if (descSort.length)
        index = this.headers.index(descSort[0]);
      $("tr td:nth-child(" + (index+1) + ")", table.tBodies[0]).each(function(row){
        $(this).addClass('sorted');
      });
    }
  });
  
  // Number formatting parsing, always difficult in JavaScript
  var NUM_CLEANER = /[$£€\,]/g;
  $.tablesorter.addParser({
    id: "newNumbers",
    is: function(s,table) {
      var newNumber   = s.replace(NUM_CLEANER, "");
      var maybeNumber = parseFloat(s, 10);
      return maybeNumber.toString() === newNumber;
    },
    format: function(s){
      return parseFloat(s, 10);
    },
    type: "numeric"
  });
  
  // Overriding format float to actually test a bit better.
  var oldFloat = $.tablesorter.formatFloat;
  $.tablesorter.formatFloat = $.tablesorter.formatInt = function(obj){
    return (obj === +obj) || (toString.call(obj) === '[object Number]') ? 0 : oldFloat(obj);
  };
  
  //initialize the table
  var table = window.table = $('#data').tablesorter({
    widgets: ['columnHighlight'],
    sortList: sortOrder//,
    //debug: true
  })
  .tablesorterPager({container: $("#pager"), positionFixed: false, size: perPage})
  .tablesorterMultiPageFilter({filterSelector: $("#filter input")});

});

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
table_setter-0.2.2 template/public/javascripts/application.js
table_setter-0.2.1 template/public/javascripts/application.js
table_setter-0.2.0 template/public/javascripts/application.js
table_setter-0.1.11 template/public/javascripts/application.js