port of http://ellislab.com/codeigniter/user-guide/libraries/table.html