Page 1 of 1

Patch to export checkbox values to XLS/CSV

Posted: Feb 3rd, '15, 04:13
by BlackLocust
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.

Re: Patch to export checkbox values to XLS/CSV

Posted: Feb 3rd, '15, 18:57
by administrator
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)

Re: Patch to export checkbox values to XLS/CSV

Posted: Feb 4th, '15, 21:46
by BlackLocust
Thanks! BlackLocust is my username. :D

Re: Patch to export checkbox values to XLS/CSV

Posted: Feb 5th, '15, 18:36
by administrator
Added 50 award points, please check yuor account.