Widget:Tableview

/* <![CDATA[ */ $(function {

// return a 1 indexed column number or null function cNumber(s) { var i, l;   s = $.trim(s.toLowerCase); if (/\d/.test(s)) { return parseInt(s, 10); } else { l = cNames.length; for (i=0; i -1) { return i+1; }     }    }    return null; } function viewTable($t) { var columns = $t.attr('data-columns'), rows = $t.attr('data-rows') cNames = []; console.log('creating a view'); console.log(' columns', columns); console.log(' rows   ', rows); if (columns) { $t.find('tr th').each(function {       cNames.push($.trim($(this).text.toLowerCase));      }); console.log('cNames', cNames); $t.find('td,th').hide; $.each(columns.split(';'), function(i, v){       var c = cNumber(v);        console.log('columns i=', i, 'value=', v);        if (c !== null) {          $t.find('td:nth-child(' + c + '),th:nth-child(' + c + ')').show;        }      }); }   if (rows) { $t.find('tr').hide; $t.find('tr>th').parent.show; rows = rows.split(';'); console.log(' split rows', rows); $.each(rows, function(i, v) {       var parts = v.toLowerCase.split('~', 2),            col, value, cell;        console.log('row filter i', i, 'v', v, 'parts', parts);        if (parts.length === 2) {          col = cNumber(parts[0]);          value = $.trim(parts[1]);          if (col >= 1) {            col = col - 1;            $t.find('tr').each(function { cell = $(this).find('td').eq(col).text.toLowerCase; if (cell.indexOf(value) > -1) { $(this).show; }           });          }        }      });    }  }

// for each "view" table on the page (that hasn't been "viewed"), //  create the view and then show the table $('.WEtableview').each(function { 	if (!$(this).hasClass('WEtableviewed')) {  		viewTable($(this));  		$(this).addClass('WEtableviewed')  		       .show('slow');  	}  }); }); /* ]]> */

This widget allows displaying just certain columns and/or rows of a table.

Parameters in data-* attributes

 * columns: a semicolon separated list of columns to be shown
 * if parameter is numeric, it is used as 1 indexed column number
 * otherwise, it is used as a case insensitive substring, and the first column heading that it matches wins


 * rows:a semicolon separated list of conditions which will cause a row to be shown, currently the only condition implemented is columnNumber~substring