Exporting Filtered Column Data issue.

Talk about Printing & Exporting Settings

Moderators: ne_moj, zewa

rayatbasix
Newbie
Newbie
Posts: 4
Joined: Aug 4th, '14, 19:22

Exporting Filtered Column Data issue.

Postby rayatbasix » Aug 4th, '14, 19:46

I've created a ENUM Multi-select list filter that filters the Columns I can see after choosing the columns from the list, then hitting "Search". It successfully returns only the columns that I want to see by building a dynamic view mode columns array. The problem is that when I go to export this "Filtered" data, it does not recognize my filtered Column choices. It instead returns the initial Unfiltered data view from the initial page load, and not the "Filtered" page load. Is there a way to have the exported or printed data show only the columns that I have "Built" from the Filtered postback instead? Here is my code below:

Code: Select all

<?php
 
header('content-type: text/html; charset=utf-8');
session_start();
define ("DATAGRID_DIR", '');                     
require_once(DATAGRID_DIR.'datagrid.class.php');

   
$DB_USER='xxxx';                       
$DB_PASS='xxxx';             
$DB_HOST='xxxx';                             
$DB_NAME='xxxx;

ob_start();
     
$debug_mode = false;

$messaging = true;

$unique_prefix = "f_"; 

$dgrid = new DataGrid($debug_mode, $messaging, $unique_prefix);

$sql = "SELECT * FROM tablename;
 
$default_order = array('Timestamp'=>'DESC');

$dgrid->DataSource("PDO", "mysql", $DB_HOST, $DB_NAME, $DB_USER, $DB_PASS, $sql, $default_order);

//$dgrid->hideGridBeforeSearch = true;

$postback_method = 'POST';

$dgrid->SetPostBackMethod($postback_method);

$layouts = array("view"=>"0", "edit"=>"0", "details"=>"1", "filter"=>"2");

$dgrid->setLayouts($layouts);

$modes = array(
    "add"         =>array("view"=>false, "edit"=>false, "type"=>"link"),
    "edit"        =>array("view"=>false, "edit"=>false,  "type"=>"link", "byFieldValue"=>""),
    "details" =>array("view"=>false, "edit"=>false, "type"=>"link"),
    "delete"  =>array("view"=>false, "edit"=>false,  "type"=>"image")
);

$dgrid->setModes($modes);

$css_class = 'x-blue';

$dgrid->SetCssClass($css_class);

$dgrid->AllowScrollingSettings(true); 

$dgrid->SetScrollingSettings('300px');

$dgrid->SetCaption("<b>Cogen Plant 'Analog Points Trend Data</b>");


\\List of Columns that my Multi-Select List Filter field uses to build list.
$ColumnsList_Array = array(
'0'=>'Timestamp',
'1'=>'UtilityKWImport',
'2'=>'Gen1KW',
'3'=>'Gen2KW',
'4'=>'CondenstateFlow',
'5'=>'CondenstateTemp',
'6'=>'HRSG1SteamFlow',
'7'=>'FeedWaterFlow',
'8'=>'Blr1SteamFlow',
'9'=>'Blr2SteamFlow',
'10'=>'Blr3SteamFlow',
'11'=>'SteamPresssure',
'12'=>'FeedWaterPress',
'13'=>'FeedWaterTemp',
'14'=>'CollegeSteamFlow',
'15'=>'COGEN_KW'
);


$filterarray = ($_POST);

$FilterColumns = array();

$iterator = new RecursiveArrayIterator($filterarray);

//Loop that builds my "Selected" Columns Filtered grid array from $_POST Data.
while ($iterator->valid()) {

    if ($iterator->hasChildren()) {
        foreach ($iterator->getChildren() as $key => $value) {
     foreach($ColumnsList_Array as $key2 => $value2) {
      if ($key2 == $value) {
       $FilterColumns[$value2] = array('header'=>$value2, 'type'=>'label', 'align'=>'left', 'width'=>'', 'wrap'=>'wrap', 'text_length'=>'-1', 'tooltip'=>'false', 'tooltip_type'=>'', 'case'=>'normal', 'summarize'=>'false', 'summarize_sign'=>'', 'sort_type'=>'string', 'sort_by'=>'', 'visible'=>'true', 'on_js_event'=>'');
              }

       }
   }
    }

    $iterator->next();
}

//Default Initial Columns before filtering.
$vm_columns = array(
'Timestamp'=>array('header'=>'Timestamp', 'type'=>'label', 'align'=>'left', 'width'=>'', 'wrap'=>'wrap', 'text_length'=>'-1', 'tooltip'=>'false', 'tooltip_type'=>'', 'case'=>'normal', 'summarize'=>'false', 'summarize_sign'=>'', 'sort_type'=>'string', 'sort_by'=>'', 'visible'=>'true', 'on_js_event'=>''),
'UtilityKWImport'=>array('header'=>'UtilityKWImport', 'type'=>'label', 'align'=>'left', 'width'=>'', 'wrap'=>'wrap', 'text_length'=>'-1', 'tooltip'=>'false', 'tooltip_type'=>'', 'case'=>'normal', 'summarize'=>'false', 'summarize_sign'=>'', 'sort_type'=>'string', 'sort_by'=>'', 'visible'=>'true', 'on_js_event'=>''),
'Gen1KW'=>array('header'=>'Gen1KW', 'type'=>'label', 'align'=>'left', 'width'=>'', 'wrap'=>'wrap', 'text_length'=>'-1', 'tooltip'=>'false', 'tooltip_type'=>'', 'case'=>'normal', 'summarize'=>'false', 'summarize_sign'=>'', 'sort_type'=>'string', 'sort_by'=>'', 'visible'=>'true', 'on_js_event'=>''),
'Gen2KW'=>array('header'=>'Gen2KW', 'type'=>'label', 'align'=>'left', 'width'=>'', 'wrap'=>'wrap', 'text_length'=>'-1', 'tooltip'=>'false', 'tooltip_type'=>'', 'case'=>'normal', 'summarize'=>'false', 'summarize_sign'=>'', 'sort_type'=>'string', 'sort_by'=>'', 'visible'=>'true', 'on_js_event'=>''),
'CondenstateFlow'=>array('header'=>'CondenstateFlow', 'type'=>'label', 'align'=>'left', 'width'=>'', 'wrap'=>'wrap', 'text_length'=>'-1', 'tooltip'=>'false', 'tooltip_type'=>'', 'case'=>'normal', 'summarize'=>'false', 'summarize_sign'=>'', 'sort_type'=>'string', 'sort_by'=>'', 'visible'=>'true', 'on_js_event'=>''),
'CondenstateTemp'=>array('header'=>'CondenstateTemp', 'type'=>'label', 'align'=>'left', 'width'=>'', 'wrap'=>'wrap', 'text_length'=>'-1', 'tooltip'=>'false', 'tooltip_type'=>'', 'case'=>'normal', 'summarize'=>'false', 'summarize_sign'=>'', 'sort_type'=>'string', 'sort_by'=>'', 'visible'=>'true', 'on_js_event'=>''),
'HRSG1SteamFlow'=>array('header'=>'HRSG1SteamFlow', 'type'=>'label', 'align'=>'left', 'width'=>'', 'wrap'=>'wrap', 'text_length'=>'-1', 'tooltip'=>'false', 'tooltip_type'=>'', 'case'=>'normal', 'summarize'=>'false', 'summarize_sign'=>'', 'sort_type'=>'string', 'sort_by'=>'', 'visible'=>'true', 'on_js_event'=>''),
'FeedWaterFlow'=>array('header'=>'FeedWaterFlow', 'type'=>'label', 'align'=>'left', 'width'=>'', 'wrap'=>'wrap', 'text_length'=>'-1', 'tooltip'=>'false', 'tooltip_type'=>'', 'case'=>'normal', 'summarize'=>'false', 'summarize_sign'=>'', 'sort_type'=>'string', 'sort_by'=>'', 'visible'=>'true', 'on_js_event'=>''),
'Blr1SteamFlow'=>array('header'=>'Blr1SteamFlow', 'type'=>'label', 'align'=>'left', 'width'=>'', 'wrap'=>'wrap', 'text_length'=>'-1', 'tooltip'=>'false', 'tooltip_type'=>'', 'case'=>'normal', 'summarize'=>'false', 'summarize_sign'=>'', 'sort_type'=>'string', 'sort_by'=>'', 'visible'=>'true', 'on_js_event'=>''),
'Blr2SteamFlow'=>array('header'=>'Blr2SteamFlow', 'type'=>'label', 'align'=>'left', 'width'=>'', 'wrap'=>'wrap', 'text_length'=>'-1', 'tooltip'=>'false', 'tooltip_type'=>'', 'case'=>'normal', 'summarize'=>'false', 'summarize_sign'=>'', 'sort_type'=>'string', 'sort_by'=>'', 'visible'=>'true', 'on_js_event'=>''),
'Blr3SteamFlow'=>array('header'=>'Blr3SteamFlow', 'type'=>'label', 'align'=>'left', 'width'=>'', 'wrap'=>'wrap', 'text_length'=>'-1', 'tooltip'=>'false', 'tooltip_type'=>'', 'case'=>'normal', 'summarize'=>'false', 'summarize_sign'=>'', 'sort_type'=>'string', 'sort_by'=>'', 'visible'=>'true', 'on_js_event'=>''),
'SteamPresssure'=>array('header'=>'SteamPresssure', 'type'=>'label', 'align'=>'left', 'width'=>'', 'wrap'=>'wrap', 'text_length'=>'-1', 'tooltip'=>'false', 'tooltip_type'=>'', 'case'=>'normal', 'summarize'=>'false', 'summarize_sign'=>'', 'sort_type'=>'string', 'sort_by'=>'', 'visible'=>'true', 'on_js_event'=>''),
'FeedWaterPress'=>array('header'=>'FeedWaterPress', 'type'=>'label', 'align'=>'left', 'width'=>'', 'wrap'=>'wrap', 'text_length'=>'-1', 'tooltip'=>'false', 'tooltip_type'=>'', 'case'=>'normal', 'summarize'=>'false', 'summarize_sign'=>'', 'sort_type'=>'string', 'sort_by'=>'', 'visible'=>'true', 'on_js_event'=>''),
'FeedWaterTemp'=>array('header'=>'FeedWaterTemp', 'type'=>'label', 'align'=>'left', 'width'=>'', 'wrap'=>'wrap', 'text_length'=>'-1', 'tooltip'=>'false', 'tooltip_type'=>'', 'case'=>'normal', 'summarize'=>'false', 'summarize_sign'=>'', 'sort_type'=>'string', 'sort_by'=>'', 'visible'=>'true', 'on_js_event'=>''),
'CollegeSteamFlow'=>array('header'=>'CollegeSteamFlow', 'type'=>'label', 'align'=>'left', 'width'=>'', 'wrap'=>'wrap', 'text_length'=>'-1', 'tooltip'=>'false', 'tooltip_type'=>'', 'case'=>'normal', 'summarize'=>'false', 'summarize_sign'=>'', 'sort_type'=>'string', 'sort_by'=>'', 'visible'=>'true', 'on_js_event'=>''),
'COGEN_KW'=>array('header'=>'COGEN_KW', 'type'=>'label', 'align'=>'left', 'width'=>'', 'wrap'=>'wrap', 'text_length'=>'-1', 'tooltip'=>'false', 'tooltip_type'=>'', 'case'=>'normal', 'summarize'=>'false', 'summarize_sign'=>'', 'sort_type'=>'string', 'sort_by'=>'', 'visible'=>'true', 'on_js_event'=>'')
);

//How I set the Viewmode upon load, first load is $vm_columns array, filtered reload is $FilterColumns array.
if (empty($filterarray)) {
$dgrid->SetColumnsInViewMode($vm_columns);
} else {
$dgrid->SetColumnsInViewMode($FilterColumns);
}

$dgrid->AllowPrinting(true);

$export_all = true;
$dgrid->AllowExporting(true, $export_all);
$exporting_types = array('csv'=>'true', 'xls'=>'true', 'pdf'=>'false', 'xml'=>'true', 'doc'=>'false');
$dgrid->AllowExportingTypes($exporting_types);

$dgrid->AllowSorting(true);

$paging_option = true;
$rows_numeration = false;
$numeration_sign = 'N #';
$dropdown_paging = false;
$dgrid->AllowPaging($paging_option, $rows_numeration, $numeration_sign, $dropdown_paging);

$bottom_paging = array('results'=>true, 'results_align'=>'left', 'pages'=>true, 'pages_align'=>'center', 'page_size'=>true, 'page_size_align'=>'right');
$top_paging = array('results'=>true, 'results_align'=>'left', 'pages'=>true, 'pages_align'=>'center', 'page_size'=>true, 'page_size_align'=>'right');
$pages_array = array('10'=>'10', '25'=>'25', '50'=>'50', '100'=>'100', '250'=>'250', '500'=>'500', '1000'=>'1000');
$default_page_size = 100;
$paging_arrows = array('first'=>'|&lt;&lt;', 'previous'=>'&lt;&lt;', 'next'=>'&gt;&gt;', 'last'=>'&gt;&gt;|');
$dgrid->SetPagingSettings($bottom_paging, $top_paging, $pages_array, $default_page_size, $paging_arrows);

## +---------------------------------------------------------------------------+
## | 5. Filter Settings:                                                       |
## +---------------------------------------------------------------------------+
##  *** set filtering option: true or false(default)
$filtering_option = true;
$show_search_type = false;
$dgrid->AllowFiltering($filtering_option, $show_search_type);
##  *** set additional filtering settings
$filtering_fields = array(
"Timestamp"=>array("type"=>"textbox", "table"=>"cogenanaloginputtrenddata", "field"=>"Timestamp", "show_operator"=>"false", "default_operator"=>"like%", "case_sensitive"=>"false", "comparison_type"=>"string", "width"=>"80px", "on_js_event"=>"", "default"=>""),   
 "From" =>array("type"=>"calendar", "field_type"=>"from", "calendar_type"=>"floating", "date_format"=>"date", "table"=>"cogenanaloginputtrenddata", "field"=>"Timestamp", "show_operator"=>"false", "default_operator"=>">=", "case_sensitive"=>"false", "comparison_type"=>"string", "width"=>"70px", "on_js_event"=>""),
 "To" =>array("type"=>"calendar", "field_type"=>"to", "calendar_type"=>"floating", "date_format"=>"date", "table"=>"cogenanaloginputtrenddata", "field"=>"Timestamp", "show_operator"=>"false", "default_operator"=>"<=", "case_sensitive"=>"false", "comparison_type"=>"string", "width"=>"70px", "on_js_event"=>""),
"Points"=>array("type"=>"enum", "table"=>"points", "field"=>"", "filter_condition"=>"", "show_operator"=>"false", "default_operator"=>"=", "case_sensitive"=>"false", "comparison_type"=>"string", "width"=>"125px", "on_js_event"=>"", "default"=>"", "source"=>$ColumnsList_Array, "view_type"=>"dropdownlist", "field_view"=>"", "order_by_field"=>"", "order_type"=>"ASC", "condition"=>"", "show_count"=>false, "multiple"=>"true", "multiple_size"=>"5")
);
$dgrid->SetFieldsFiltering($filtering_fields);

$dgrid->AllowDefaultFiltering(true);

$dgrid->Bind();
ob_end_flush();
?>


I have tried adjusting the "export_all" setting to both true and false, and it did not help.
Also, I do not access this page with any URL parameters (my URL is http://localhost/datagrid/mypage.php).

Any help would be appreciated.

administrator
Site Admin
Site Admin
Posts: 5939
Joined: Jan 7th, '09, 23:18
Contact:

Re: Exporting Filtered Column Data issue.

Postby administrator » Aug 5th, '14, 06:03

Exporting routing doesn't know what type of columns set you're using.
That's the reason why you don't get the request columns in exporting.

One of possible solutions may be to use some additional parameter as a flag, for example : colset=1 or colset=2
So, you also have to use:

## +-- Passing parameters & setting up other DataGrids ------------------------+
## *** set variables that used to get access to the page (like: my_page.php?act=34&id=56 etc.)
$http_get_vars = array('colset');
$dgrid->SetHttpGetVars($http_get_vars);

rayatbasix
Newbie
Newbie
Posts: 4
Joined: Aug 4th, '14, 19:22

Re: Exporting Filtered Column Data issue.

Postby rayatbasix » Aug 5th, '14, 20:14

Thanks for the info.

How and what do I pass in these URL parameters to, your download.php and/or datagrid.class.php files?

What existing code would I modify in any or all of the php pages in order to have the export function correctly use this filtered column data?

Does the below code snippet get placed in all above mentioned php files, or just mypage.php?:

Code: Select all

$http_get_vars = array('colset');
$dgrid->SetHttpGetVars($http_get_vars);


Thanks again for all the help. I'm a little new at php and passing parameters, etc.


rayatbasix
Newbie
Newbie
Posts: 4
Joined: Aug 4th, '14, 19:22

Re: Exporting Filtered Column Data issue.

Postby rayatbasix » Aug 7th, '14, 15:51

I apologize in advance for my lack of understanding, but that article does not seem to help me with my questions.

I have placed the code:

Code: Select all

$http_get_vars = array('colset');
$dgrid->SetHttpGetVars($http_get_vars);
In my datagrid php page.

As a test, I am accessing my grid page like so: http://localhost/mypage.php?colset=1.

While in debugging mode, I can see that accessing my page with a parameter "colset" stores a value in my _POST array on initial load, and also places it in the _GET array output after clicking the search button for the filter form.

I'm confused on how I use this 'colset' parameter to affect the export or print to only show my filtered column choices?
The export operation seems to filter correctly for the other filter fields such as my Date range fields and my text box filter fields, just not my multi-select columns filter field.

P.S. I sent you a PM with a url link to my grid page with debugging on.

Sorry to be a pain, I guess i'm not understanding how to take this further.

Thanks.

rayatbasix
Newbie
Newbie
Posts: 4
Joined: Aug 4th, '14, 19:22

Re: Exporting Filtered Column Data issue.

Postby rayatbasix » Aug 8th, '14, 19:37

Nevermind, I fixed it by using the following in my code:

Replaced:
$filterarray = ($_POST);

With:
$filterarray = ($_REQUEST);

Exporting is working fine now with filtered columns.


Return to “Settings: Printing & Exporting”