tables_on_cows

MooTools based table sort and pagination. Quick and slim.

MIT License

Stars
17

This script is a fast and slim table sort and table pagination based on MooTools. It's based on these blog posts:

http://madhatted.com/2008/1/11/the-joy-of-a-minimal-complete-javascript-table-sort http://madhatted.com/2008/1/16/the-joy-of-an-optimized-complete-javascript-table-sort http://madhatted.com/2008/6/20/the-joy-of-tables-on-cows

A simple example:

new SortingTable( 'sort_table' );

A complex example:

You could also use the 'details' setting to say you have expanding rows. The defaults and options are:

new SortingTable( 'my_table', { zebra: true, // Stripe the table, also on initialize details: false, // Has details every other row paginator: false, // Pass a paginator object dont_sort_class: 'nosort', // Class name on th's that don't sort forward_sort_class: 'forward_sort', // Class applied to forward sort th's reverse_sort_class: 'reverse_sort' // Class applied to reverse sort th's });

new PaginatingTable( 'my_table', 'ul_for_paginating', { per_page: 10, // How many rows per page? current_page: 1, // What page to start on when initialized offset_el: false, // What dom element to stick the offset in cutoff_el: false, // What dom element to stick the cutoff in details: false // Do we have hidden/collapsable rows? });

You could also pass an array of paginators instead of just a string.

The formats sorted out of the box are:

  • strings
  • numbers
  • decimal currency (12.34, 4.50)
  • dates (YYYY-MM-DD, YYYY-M-D)
  • relative dates (1 day ago, 38 years ago)
  • disk memory (1.75 MB, 34 KB, 8 TB)

Adding a new conversion is pretty easy. They look like this:

  // YYYY-MM-DD, YYYY-m-d
  { matcher: /(\d{4})-(\d{1,2})-(\d{1,2})/,
    conversion_function: function( row ) {
      var cell = $(row.row.getElementsByTagName('td')[this.sort_column]).get('text');
      cell = this.conversion_matcher.exec( cell );
      return new Date(parseInt(cell[1]), parseInt(cell[2], 10) - 1, parseInt(cell[3], 10));
    }
  },

And you add them to the conversion_filters array.

Related Projects