Sortable Tables with Awstats

Last updated: April, 2010

Description:

Awstats is a freeware log file analyzer. It generates a set of (on demand) web pages displaying information who visted your webite and what pages the visitors viewed. Unfortunately the tables on these pages can not be sorted (not until version 6.95 at least). The files below contain modifications that insert some information which references to javascript to sort these tables. These modifications are tested with the static generation of Awstats pages.

To accomplish sortable tables, the following was done:

  • Look at the generated Awstats html pages, and see what columns you would like to sort.
  • In the awstats.pl file, add a reference to the two Javascript files:
    • print "<script type=\"text/javascript\" src=\"tablesort.js\"></script>";
    • print "<script type=\"text/javascript\" src=\"customsort.js\"></script>";
  • Find the 'Message' array in the awstats.pl file.
  • Find the position of the table header of the column you want to sort
  • Find in the awstats.pl file all statements that print table headers and the position in the Message table that corresponds with your column. E.g.: the 'last visits' column at position 9 in the Message array. Now look for these kinds of statements in the awstats.pl file:
    • print "<th rowspan=\"2\" width=\"120\">$Message[9]</th>";
  • Check what Javascript function you need to use (this depends on the format of the column) and modify the above statement something like this (sortable is the default sort, but there are also formats such as sortDutchCurrencyValues, sortable-sortFileSize). If you use other than the default sort, you need to include the default sort. See below for some examples.
    • print "<th class=\"sortable\" rowspan=\"2\" width=\"120\">$Message[9]</th>";
    • "<th class=\"sortable-sortFileSize\" bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>";
    • "<th class=\"sortable-sortDutchCurrencyValues\" bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th>";