Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Tanith on Jul 01, 2009 07:57
open dhtmlx forum
Problem exporting Grid to CSV

Hello,

i have a problem with my export from dthmlxgrid to csv. The result of the export is like that :

head_col1;head_col2;head_col3;head_col4;head_col5 val1_col1;val1_col2;val1_col3;val1_col4;va1_col5 val2_col1;val2_col2;...

all the export is in one line, and there is a space between "lines" whereas it should be a carriage return.

I expected something like that :

head_col1;head_col2;head_col3;head_col4;head_col5;
val_col1;val_col2;val_col3;val_col4;val_col5;
val2_col1;val2_col2;...

The code i'm using is :

function exportMonTableau()
        {
            monTableau.setCSVDelimiter(";");
            monTableau.enableCSVHeader(true);
            var contenu = monTableau.serializeToCSV();
            document.getElementById('contenu').innerHTML = contenu;
            document.getElementById('FmFormulaire').submit();
        }

contenu is a textarea.

Did i forget a parameter ?
Answer posted by dhxSupport on Jul 01, 2009 08:43
To display contenu string correctly in the textarea you should replace blank space to the carriage return symbol ("\n"):
function exportMonTableau() 
  { 
  monTableau.setCSVDelimiter(";"); 
  monTableau.enableCSVHeader(true); 
  var contenu = monTableau.serializeToCSV(); 
  document.getElementById('contenu').innerHTML = contenu.replace(/ /g,"\n"); 
  document.getElementById('FmFormulaire').submit(); 
  }

Answer posted by tanith on Jul 01, 2009 11:08
I cannot do that, cell's values can contain spaces.
Answer posted on Jul 02, 2009 08:49

Try to change your code like that:

function exportMonTableau() 
  { 
  monTableau.setCSVDelimiter(";"); 
  monTableau.enableCSVHeader(true); 
  monTableau.csv.row="\n";
  var contenu = monTableau.serializeToCSV(); 
  document.getElementById('contenu').innerHTML = contenu;
  document.getElementById('FmFormulaire').submit(); 
  }

Answer posted on Jul 02, 2009 09:01
Surprise ! monTableau.csv.row is already equals to '\n'./ I didn't know that.

Maybe the problem occurs because i put the csv into a textarea. Keep it spaces and carriage return ?...

I continue to search.
Answer posted on Jul 02, 2009 09:14
Shame on me...

function exportMonTableau()
        {
            monTableau.setCSVDelimiter(";");
            monTableau.enableCSVHeader(true);
            var contenu = monTableau.serializeToCSV();
            document.getElementById('contenu').value = contenu; <-- .value not .innerHTML
            document.getElementById('FmFormulaire').submit();
        }

T_T