Patch to export checkbox values to XLS/CSV

Talk about Printing & Exporting Settings

Moderators: ne_moj, zewa

BlackLocust
Senior
Senior
Posts: 34
Joined: Sep 16th, '09, 23:17

Patch to export checkbox values to XLS/CSV

Postby BlackLocust » Feb 3rd, '15, 04:13

I find that when I export a grid that has checkboxes to XLS or CSV, those columns export blank. I would prefer to export the underlying data value and permit the Excel user to format as he pleases.

This additional line of code does that. (I'm working with version 7.9.9)

Code: Select all

protected function GetFieldValueByType($field_value, $ind, $row, $field_name='', $m_field_req_type='', $mode='', $multirow_postfix=''){
...

        if($mode === 'view'){
...
                switch($field_type){
...
                    case 'checkbox':
                        $checked = '';
                        $full_field_name = 'sy'.$field_name.$multirow_postfix;
                        $row_id = $this->GetRecordID($row);
                        $fp_true_value = $this->GetFieldProperty($field_name, 'true_value', 'view');
                        $fp_false_value = $this->GetFieldProperty($field_name, 'false_value', 'view');
                        $fp_readonly    = $this->GetFieldPropertyBool($field_name, 'readonly', 'view', false, false);
                        $pk_value = isset($row[$this->GetFieldOffset($this->primaryKey)]) ? '_'.$row[$this->GetFieldOffset($this->primaryKey)] : '';
                        if($fp_readonly) $readonly = 'disabled';
                        else $readonly = '';                 

                        $new_field_value = $fp_true_value;
                        if(($fp_true_value !== '') && ($fp_false_value !== '')){
                            if($field_value == $fp_true_value){
                                $checked = 'checked="checked"';
                                $new_field_value = $fp_false_value;
                            }else{
                                $new_field_value = $fp_true_value;
                            }
                        }
         
         //Simplified formatting of checkbox in the case that it's exporting to CSV or XLS -- BlackLocust
         if ($this->GetVariableAlpha('export_type')=='csv' || $this->GetVariableAlpha('export_type')=='xls') return $field_value;
         
                        $href_string = '';
                        $this->SetUrlString($href_string, '', 'sorting', 'paging', '&');
                        $on_change = 'onclick="if(confirm(\''.$this->lang['alert_perform_operation'].'\')){'.$this->uniquePrefix.'_doPostBack(\'toggle_status\',\''.Helper::EncodeParameter($row_id, $this->safeMode).'\',\''.$href_string.'&'.$this->uniquePrefix.'toggle_status=1&'.$this->uniquePrefix.'toggle_field='.$field_name.'&'.$this->uniquePrefix.'toggle_field_value='.$new_field_value.'\');}else{_dgStopPropagation(event);return false;};"';
                        $output = '<input '.$on_change.' class="'.$this->cssClass.'_dg_checkbox" type="checkbox" name="'.$full_field_name.'" id="'.$full_field_name.$pk_value.'" title="'.$this->GetFieldTitle($field_name).'" value="'.trim($field_value).'" '.$checked.' '.$readonly.' '.$on_js_event.' />';
                        break;



It's the line right below my comment ... that in the code box is indented wrong.

Hope it helps somebody else. :) Of course, if you have a better suggestion, I'll probably implement that. But for the moment, this is helping me.

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

Re: Patch to export checkbox values to XLS/CSV

Postby administrator » Feb 3rd, '15, 18:57

Thanks, yuor patch is accepted.
Please send us yuor username, so we could give you award bonus points (you my redeem them on next purchasing)

BlackLocust
Senior
Senior
Posts: 34
Joined: Sep 16th, '09, 23:17

Re: Patch to export checkbox values to XLS/CSV

Postby BlackLocust » Feb 4th, '15, 21:46

Thanks! BlackLocust is my username. :D

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

Re: Patch to export checkbox values to XLS/CSV

Postby administrator » Feb 5th, '15, 18:36

Added 50 award points, please check yuor account.


Return to “Settings: Printing & Exporting”