Below is the Code, you can create the listing page with sortable header and pagination. This code using the 'TableSort' theme.
function custom_table_menu(){
$items = array();
$items['custom_table'] = array(
'title' => 'Custom Table',
'page callback' => 'order_listing',
'access callback' => TRUE,
);
return $items;
}
function order_listing() {
global $base_url;
$header = array(
array(
'data' => t('OrderID'),
'field' => 't.OrderID',
),
array(
'data' => t('OrderDate'),
'field' => 't.OrderDate',
),
array(
'data' => t('PaymentAmount'),
'field' => 't.PaymentAmount',
),
array(
'data' => t('BillingFirstName'),
'field' => 't.BillingFirstName',
),
array(
'data' => t('BillingLastName'),
'field' => 't.BillingLastName',
),
array(
'data' => t('OrderStatus'),
'field' => 't.OrderStatus',
),
array(
'data' => t('ShipDate'),
'field' => 't.ShipDate',
),
);
$cust_id = arg(2);
$query = db_select('Orders', 't')->extend('TableSort');
$query->fields('t', array('OrderID', 'OrderDate', 'PaymentAmount', 'BillingFirstName', 'BillingLastName', 'OrderStatus', 'ShipDate'));
$table_sort = $query->extend('TableSort')->orderByHeader($header);
$pager = $table_sort->extend('PagerDefault')->limit(50); // 5 rows per page.
$result = $pager->execute();
$rows = array();
foreach ($result as $row) {
$rows[] = array('data' => array( $row->OrderID, $row->OrderDate, $row->PaymentAmount, $row->BillingFirstName, $row->BillingLastName, $row->OrderStatus, $row->ShipDate));
}
$output .= theme('pager');
$output .= theme('table', array('header' => $header, 'rows' => $rows, "empty" => t("No Records Found"), 'attributes' => array('id' => 'sort-table', 'class' => array('tbl-data'))));
$output .= theme('pager');
return $output;
}