I have custom reporting which has few dropdowns. A report is generated in the form of a table with selected dropdown values.
I have tried adding pager to the table.
When I click on next page, all the form values loose their form state and page is reloaded back and table gets disappeared.
Im using 'drupal_get_form' in pagecallback in the menu items list.
Here is the code to generate report.
/**
* Method to implement menu for this page
*
* @return multitype:multitype:string multitype:string
*/
function dm_reports_menu() {
return array (
'dm_reports' => array (
'title' => 'Reports',
'page callback' => 'drupal_get_form',
'page arguments' => array (
'dm_reports_form'
),
'access callback' => 'user_access',
'access arguments' => array (
'administer dm_reports'
)
)
);
}
/**
* Method to submit the form and generate report
*
* @param unknown $form
* @param unknown $form_state
*/
function dm_reports_form_submit($form, &$form_state) {
$circle_name = $form_state ['values'] ['circle_name'];
$report_type = $form_state ['values'] ['choose_report'];
$system_type = $form_state ['values'] ['system_type'];
$office_name = $form_state ['values'] ['office_name'];
$migration_type = $form_state ['values'] ['migration_type'];
$from_date = get_date_SQL ( $form_state ['input'] ['from_date'] );
$to_date = get_date_SQL ( $form_state ['input'] ['to_date'] );
$plan_type = $form_state ['values'] ['plan_type'];
$phase_type = $form_state ['values'] ['phase'];
$vendor_name=$form_state ['values'] ['vendor_name'];
if ($form_state ['values'] ['op'] == 'Generate Report') {
// Report header
$header = get_header_data ( $report_type, $system_type );
$rows = array ();
// Get rows data
try {
$rows = get_row_data ( $report_type, $circle_name, $office_name, $system_type, $migration_type, $from_date, $to_date, $plan_type, $form_state,$phase_type,$vendor_name );
} catch ( Exception $e ) {
form_set_error ( '', t ( 'Error occurred. Please try again, or report a problem to administrator.'.$e ) );
watchdog ( 'atm_status', $e->getMessage (), NULL, WATCHDOG_ERROR );
}
$report_name = '';
if (sizeof ( $rows ) > 0) {
$report_name = $report_type .'_' . date ( 'd_M_Y_H_i_s', time () ) . '.xls';
// generate_xls ( $header, $rows, $report_name);
}
$form_state ['report_name'] = $report_name;
// build the results table
$form_state['results_table'] = array (
'#title' => $report_type,
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
'#sticky' => TRUE,
'#empty' => t ( 'NO DATA FOUND.' )
// '#prefix' => '<hr><strong>' . $report_type . '</strong><div style="width: 720px; height: 300px; overflow: auto;">',
// '#suffix' => '</div>'
);
$form_state ['rebuild'] = TRUE;
}
}
function get_dm_issues_data($circle_name,$office_name)
{
$rows = array ();
$query = db_select('dm_issues', 'di')
->extend('PagerDefault')
->limit(3)
->fields('di');
$results = $query->execute();
foreach ( $results as $node ) {
$rows [] = array (
$node->de_date,
$node->po_name,
//$node->weg_code,
$node->kvp_duplicates,
$node->nsc_duplicates,
$node->duplicate_int_ent,
$node->no_int,
$node->nominee_grt_one,
$node->account_his_na,
$node->comments
);
}
return $rows;
}
Any help would ne appreciated.