function tablesort_example_page() {
print l('<button class="btn btn-default">' . t('Add New Country') . '</button>', 'mypages/countries/' . $term->tid, array('html' => TRUE));
And also i want display the above print button on the top to table....
We are going to output the results in a table with a nice header. The header gives the table the information it needs in order to make the query calls for ordering. TableSort uses the field information to know what database column to sort by.
$header = array(
array('data' => t('S No'), 'field' => 't.id'),
array('data' => t('Country Name'), 'field' => 't.country_name'),
array('data' => t('Status'), 'field' => 't.status'),
array('data' => t('Added Date'), 'field' => 't.added_date'),
array('data' => t('Action'), 'field' => 't.id',),
array('data' => t('Action'), '',),
);
Using the TableSort Extender is what tells the the query object that we are sorting.
$limit = 10;
$query = db_select('countries', 't')->extend('TableSort')->extend('PagerDefault')->limit($limit)->orderby('country_name', ASC);
$query->fields('t');
Don't forget to tell the query object how to find the header information.
$result = $query
->orderByHeader($header)
->execute();
this is displaying table
$rows = array();
$i=1;
foreach ($result as $row) {
//print_r($row);
// Normally we would add some nice formatting to our rows
// but for our purpose we are simply going to add our row
// to the array.
$rows[] = array(
$i,
//$row->id,
$row->country_name,
$status = ($row->status == 0) ? 'Inactive' : 'Active',
//$row->added_date,
date('d-m-Y H:i:s', strtotime($row->added_date)),
l('Edit', 'mypages/countries/'. $row->id),
l('Delete', 'mypages/delete/'. $row->country_name)
);
$i++;
}
here pagination not getting loop in next pages..next pages starting from 1 ..