<?php

class My_List_Table extends WP_List_Table {

	function My_List_Table() {
		parent::WP_List_Table( array(
			'items',
		) );
	}
	
	function prepare_items() {
		$this->items = $this->get_items();

		$this->set_pagination_args( array(
			'total_items' => 10,
			'per_page' => 5
		) );
	}

	function check_permissions() {
		if ( !current_user_can('manage_options') )
			wp_die(__('Cheatin&#8217; uh?'));
	}

	function get_columns() {
		return array(
			'cb'    => '<input type="checkbox" />',
			'name'  => __( 'Name', 'cck' ),
			'color' => __( 'Color', 'cck' ),
		);
	}
	
	function get_sortable_columns() {
		return array(
			'name' => 'name',
		);
	}

	function column_cb( $item ) {
		return '<input type="checkbox" name="delete_items[]" value="' . $item->id . '">';
	}
	
	function column_name( $item ) {
		return $item->name;
	}

	function column_color( $item ) {
		return $item->color;
	}
	
	function column_default( $item, $column_name ) {
		return apply_filters( 'manage_items_custom_column', '', $column_name, $item->id );
	}
	
	function get_items() {
		$items = array();

		$page = $this->get_pagenum();

		$range = range(($page-1) * 5, $page * 5);
		if ( isset( $_REQUEST['order'] ) && 'desc' == $_REQUEST['order'] )
			$range = array_reverse($range);

		foreach ( $range as $i ) {
			$items[] = (object) array(
				'id' => $i,
				'name' => "Item " . zeroise($i, 2),
				'color' => 'red',
			);
		}

		return $items;
	}
}

