Export to CSV?

Dear sirs

As my datalists are really long, i always got problems with exporting to excel. Is there a way to export to a simple “.csv” file as to “.xlsx” ?

If not you maybe have any ideas how i can realize that?

Thank you in advance and best regards
Oliver

Here you can find a tutorial about serialization the grid to CSV:
docs.dhtmlx.com/doku.php?id=dhtm … ion_to_csv

Hmm … i have any mistake? If i debug he always dies in ROW: 3

1:  Grid[grid].setSerializationLevel(true, true);
2:  Grid[grid].csv.cell = "\t";
3:  var CSVStr = Grid[grid].serializeToCSV();

I tried the following in XML and works:

1:  Grid[grid].setSerializationLevel(true, true);
2:  var XMLStr = Grid[grid].serialize();

?

Directly a second question. Is there a way to send something different like a GRID to excel?
Something like:

Grid[grid].setSerializationLevel(true, true);
var XMLStr = Grid[grid].serialize();
XMLStr.toExcel(path);

I ask because i would like to create a little form where i can select data directly from the database … without loading in a grid.

Here you can find the working example of serialization the grid to CSV:
dhtmlx.com/docs/products/dht … d_csv.html

setSerializationLevel() method allows to cofigure the serialization to XML only. It is not working in case of serialization to CSV

For export to Excel please, have a look at the following tutorial:
docs.dhtmlx.com/doku.php?id=dhtmlxgrid:excel

I checked the example and i did it the same. I think there’s something blocking … but what?
GRID

<?php 
   require_once('../../host/config_sql.php'); 
   $jahr = $_GET['a'];
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <title>Gesamtauftragsliste</title>
      <link href="../dhtmlx/Grid/codebase/dhtmlxgrid.css" rel="stylesheet" type="text/css">  
      <link href="../dhtmlx/Grid/codebase/ext/dhtmlxgrid_pgn_bricks.css" rel="stylesheet" type="text/css">
      <link href="../dhtmlx/Grid/codebase/skins/dhtmlxgrid_dhx_skyblue.css" rel="stylesheet" type="text/css">
      <link href="../dhtmlx/Toolbar/skins/dhtmlxtoolbar_dhx_skyblue.css" rel="stylesheet" type="text/css">  
      
      <script src="../js/toolbar.js"></script>
      <script src="../js/dispotool.js"></script>
      <script src="../dhtmlx/Toolbar/dhtmlxcommon.js"></script>
      <script src="../dhtmlx/Toolbar/dhtmlxtoolbar.js"></script> 
      <script src="../dhtmlx/Grid/codebase/dhtmlxcommon.js"></script>
      <script src="../dhtmlx/Grid/codebase/dhtmlxgrid.js"></script>        
      <script src="../dhtmlx/Grid/codebase/dhtmlxgridcell.js"></script>
      <script src="../dhtmlx/Grid/codebase/excells/dhtmlxgrid_excell_grid.js"></script>
      <script src="../dhtmlx/Grid/codebase/ext/dhtmlxgrid_filter.js" type="text/javascript"></script> 
      <script src="../dhtmlx/Grid/codebase/ext/dhtmlxgrid_pgn.js"></script>
      <script src="../dhtmlx/Grid/codebase/ext/dhtmlxgrid_nxml.js"></script>
      <script src="../dhtmlx/Grid/codebase/ext/dhtmlxgrid_hmenu.js"></script>
      <script src="../dhtmlx/Grid/codebase/ext/dhtmlxgrid_export.js"></script>
      <script src="../dhtmlx/Grid/codebase/ext/dhtmlxgrid_splt.js"></script>
      <script src="../dhtmlx/Connector/connector.js"></script>
        
      <style>
	      html, body {width: 100%; height: 100%; margin: 0px; overflow: hidden; background-color:white;}
	     .grid_hover {background-color:#9CC;font-size:20px;}
		 .rows_even {background-color:#DFEFFF;}
		 .rows_uneven {background-color:#FFFFF0;}
		 .dhx_header_cmenu{background-color:#ffffff;border:2px outset silver;z-index:2;}
		 .dhx_header_cmenu_item{white-space:nowrap;}
      </style>
      
   </head>

   <body onload="doOnLoad(); Grid_laden();" id="fullscreen"> 
      <div style="position:relative; height:100%; width:100%">
         <table width="100%">
            <tr>
               <td width="67%"><div id="toolbarbox"></div></td>
               <td width="33%"><div id="paging"></div></td>
            </tr>
         </table>
         <div id="gridbox" style="width: 99%; height: 96%; background-color: white"></div>
         <div id="loading" style="position:absolute; top:50%; left:47%; height:20px; widht:130px;"><img src="../dhtmlx/Grid/codebase/imgs/loading.gif" width="128" height="15" /></div> 
      </div>       
      
	  <script type="text/javascript">
		 Grid = new Array();
		 
		 function doOnLoad() {
		    var xmlHttp = null;
			
			if (typeof XMLHttpRequest != 'undefined') { xmlHttp = new XMLHttpRequest(); }
            if (!xmlHttp) { 
               try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {
	           try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { xmlHttp  = null; } }
            }
				
            if (xmlHttp) {
	           var url = "../sql/update.php";
			   var params = "Merker=43";
			   
			   xmlHttp.open("POST", url, true);
			   xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=UTF-8");
			   xmlHttp.setRequestHeader("Content-length", params.length);
			   xmlHttp.setRequestHeader("Connection", "close");
			   xmlHttp.send(params);
			}
		 };
		 
		 function Grid_laden() {
	        var jahre   = [['ges_jahr11', 'obj', '2011', 'Go.png'],['ges_jahr12', 'obj', '2012', 'Go.png'],['ges_jahr13', 'obj', '2013', 'Go.png']]; 
			var Toolbar = new dhtmlXToolbarObject("toolbarbox", "dhx_black");
		    Toolbar.setIconsPath("../images/icons/");
		    Toolbar.setSkin('dhx_skyblue');	
			Toolbar.addButton("new_gesamt", 0, "&nbsp;Aufträge aktualisieren", "Sync.png", "Sync.png");
		    Toolbar.addButton("excel3", 1, "&nbsp;Excel", "excel.png", "excel.png");
			Toolbar.addButton("csv", 2, "&nbsp;CSV", "excel.png", "excel.png");
			Toolbar.addButton("logout", 3, "&nbsp;LogOut", "Exit.png", "Exit.png");
			Toolbar.addText("jahr1", 4, "Jahr: ");
			Toolbar.addButtonSelect("jahre", 5, "<?php echo $jahr; ?>", jahre, "", "", true, false);
			Toolbar.addText("header", NaN, '<span style="color:#900;font-weight:bold;padding-left:270px">MDSKOM GmbH&nbsp;&nbsp;&nbsp;-&nbsp;&nbsp;&nbsp;G E S A M T A U F T R A G S L I S T E</span>');
		    Toolbar.addSeparator("s1", 1); 
			Toolbar.addSeparator("s1", 4);
			Toolbar.addSeparator("s1", 6); 
			Toolbar.addSeparator("s1", 9);
		    Toolbar.attachEvent("onClick", function(id) { Button_laden(id,1,1); });
		 
			Grid[1] = new dhtmlXGridObject('gridbox');
		    Grid[1].setImagePath("../dhtmlx/Grid/codebase/imgs/");
		    Grid[1].setHeader("WO<br>Intern,WO<br>UM,KDNR,Eingang,Typ,Abt.,Erledigt,Gebiet,Techniker,Disponent,Termin,Termin Start,Termin Ende,Abgemeldet,KW,Kostenstelle,Abbruch,Storno,Storno<br>vorgemerkt,Folgeticket,Anlage,Wartung,Spintool<br>genehmigt,Spintool<br>Summe,UP Adresse,Kunde,Strasse,HsNr,Zus,PLZ,Ort,Ausgeführte Arbeiten,Memo,Abbruch");
			Grid[1].attachHeader("#connector_text_filter,#connector_text_filter,#connector_text_filter,#connector_text_filter,#connector_select_filter,#connector_select_filter,#connector_select_filter,#connector_text_filter,#connector_select_filter,#connector_select_filter,#connector_text_filter,#connector_text_filter,#connector_text_filter,#connector_text_filter,#connector_text_filter,#connector_select_filter,#connector_select_filter,#connector_select_filter,#connector_select_filter,#connector_select_filter,#connector_text_filter,#connector_select_filter,#connector_text_filter,#connector_text_filter,#connector_text_filter,#connector_text_filter,#connector_text_filter,#connector_text_filter,#connector_text_filter,#connector_text_filter,#connector_text_filter,#connector_text_filter,#connector_text_filter,#connector_text_filter");
		    Grid[1].setInitWidths("60,55,70,100,40,60,60,70,90,90,100,100,100,100,37,95,200,200,200,90,60,70,150,65,250,120,200,40,40,50,120,350,350,350");
		    Grid[1].setColAlign("center,center,center,center,center,center,center,center,center,center,center,center,center,center,center,center,left,left,left,center,center,center,center,center,left,left,left,center,center,center,left,left,left,left");
		    Grid[1].setColTypes("ro,ro,ro,ro,ro,coro,coro,coro,coro,coro,ro,ro,ro,ro,ro,coro,coro,coro,coro,coro,ro,coro,ro,ro,ro,ro,ro,ro,ro,ro,ro,ro,ro,ro");
			Grid[1].setColumnColor("#FFC,#FFC,#FFC");
		    Grid[1].enableTooltips("false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,true,true,true,false,false,false,false,false,true,false,true,false,false,false,false,true,true,true");
			Grid[1].setColSorting("connector,connector,connector,connector,connector,connector,connector,connector,connector,connector,connector,connector,connector,connector,connector,connector,connector,connector,connector,connector,connector,connector,connector,connector,connector,connector,connector,connector,connector,connector,connector,connector,connector,connector");
	        Grid[1].enableRowsHover(true, 'grid_hover'); 
	        Grid[1].attachEvent("onXLS", function() {document.getElementById('loading').style.display = 'block';});
	        Grid[1].attachEvent("onXLE", function() {document.getElementById('loading').style.display = 'none';});
			Grid[1].attachEvent("onEditCell", function(stage,rId,cInd,nValue,oValue){ 
			   if (stage == 0 && (cInd == 5 || cInd == 6 || cInd == 7 || cInd == 8 || cInd == 9 || cInd == 15 || cInd == 16  || cInd == 17 || cInd == 18 || cInd == 19 || cInd == 21)) { return false; } 
			});
		    Grid[1].setSkin("clear");
			Grid[1].enableMultiline(true);
		    Grid[1].enablePaging(true, 90, 10, "paging", true);
	        Grid[1].setPagingSkin("toolbar", "dhx_skyblue");
	        Grid[1].init();
	        Grid[1].enableHeaderMenu();
			Grid[1].splitAt(3);
			Grid[1].enableCSVAutoID(false);
	        Grid[1].enableAlterCss("rows_even", "rows_uneven");
			Grid[1].load("../dhtmlx/Data/XML/connector.php?id=7&jahr=<?php echo $jahr; ?>"); 
		 };			 
      </script> 
   </body>
</html>

TOOlBAR LINK

function Button_laden(button,tab,grid,wid,form_id,wonr,user) {
   switch (button) {
	  case "csv":   
        Grid[grid].setCSVDelimiter(';'); 
        alert(Grid[grid].serializeToCSV());
	     break;
   }	
};

My excel export is working without problems. My question is if there’s a possibility to select some data directly in the database, put them in a string, array, … whatever …, and send them to excel.

Thank you for your help

Unfortunately your issue with serialization cannot be reconstructed locally.
Please, provide a complete demo or a demo link where it can be reconstructed

Export to Excel is available directly from the database.
But there are some specificities:
grid structure should be configured on the srever-side, also issues may occur with a big mount of data in your grid.

Here is the example of server side code with the function generating an excel:

[code]$res = mysql_connect($mysql_server, $mysql_user, $mysql_pass);
mysql_select_db($mysql_db, $res);

$grid = new GridConnector($res);
$grid->set_config(new GridConfiguration());

$grid->event->attach(“beforeOutput”, “export”);
$fields = “item_nm,item_cd”;
$grid->render_table(“grid50”, “item_id”, $fields);

function export($grid, $out) {
$xml = simplexml_load_string($out->__toString());
$pdf = new gridExcelGenerator();
$pdf->printGrid($xml);
die();
}[/code]