1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
|
<html>
<head>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=iso-8859-1">
<title>Test fichier CSV</title>
<link rel="stylesheet" type="text/css" media="screen" href="css/jquery-ui-1.8.17/jquery-ui-1.8.17.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("jquery", "1");
google.load("jqueryui", "1");
</script>
<script type="text/javascript" src="js/i18n/grid.locale-fr.js"></script>
<!--<script type="text/javascript" src="js/i18n/grid.locale-ja.js"></script>-->
<script type="text/javascript" src="js/jquery.jqGrid.src.js" ></script>
<!-- See http://code.google.com/p/jquerycsvtotable/ -->
<script src="js/jquery.csvToTable.js" type="text/javascript"></script>
<style type="text/css">
html,
body {
margin: 0;
padding: 0;
}
/* CSV Table Classes */
TABLE.CSVTable {
font: 0.8em Verdana,Arial,Geneva,Helvetica,sans-serif;
border-collapse: collapse;
width: 450px;
}
/* Header */
TABLE.CSVTable THEAD TR {
background: #E8EDFF;
}
TABLE.CSVTable TH {
font-family: "Lucida Sans Unicode","Lucida Grande",Sans-Serif;
font-size: 1.2em;
}
/* Table Cells */
TABLE.CSVTable TD, TABLE.CSVTable TH {
padding: 8px;
text-align: left;
border-bottom: 1px solid #FFFFFF;
border-top: 1px solid transparent;
}
/* Default background color for rows */
TABLE.CSVTable TR {
background: #F0F0F0;
}
/* Background color for odd rows */
TABLE.CSVTable TR.odd {
background: #F9F9F9;
}
/* Hover color for all rows */
TABLE.CSVTable TR:hover {
background: #E8EDFF;
}
</style>
<script type="text/javascript">
$(function() {
"use strict";
jQuery.get('data.csv', function(data) {
$('#CSVSource').html('<pre>' + data + '</pre>');
});
$("#export-to-csv").click( function() {
exportExcel("treegrid");
});
$("#table-to-grid").click( function() {
tableToGrid("#table", { width: 300, height: 'auto'});
});
$("#csv-to-table").click( function() {
$('#view-csv').CSVToTable('data.csv');
});
// See http://stackoverflow.com/questions/2188762/php-jqgrid-export-to-excel
function exportExcel(grid_id) {
var grid = $("#" + grid_id)
var mya = new Array();
var colNames = new Array();
var i = 0, j = 0, ii = 0;
var csv = "";
mya = grid.getDataIDs(); // Get All IDs
var data = grid.getRowData(mya[0]); // Get First row to get the labels
for (i in data) { colNames[ii++] = i; } // capture col names
for(i = 0; i <colNames.length; i++) {
csv = csv + colNames[i] + "\t"; // output each Column as tab delimited
}
csv = csv + "\n";
for(i = 0; i < mya.length; i++) {
data = grid.getRowData(mya[i]); // get each row
for( j = 0; j < colNames.length; j++) {
csv = csv + data[colNames[j]]+"\t"; // output each column as tab delimited
}
csv = csv + "\n"; // output each row with end of line
}
csv = csv + "\n"; // end of line at the end
// alert(csv);
document.forms[0].csvBuffer.value = csv;
document.forms[0].method = 'POST';
// send it to server which will open this contents in excel file
document.forms[0].action = 'http://localhost:3000/Exemple 2';
document.forms[0].target = '_blank';
document.forms[0].submit();
};
$("#treegrid").jqGrid({
url:'json/tree.json',
datatype: 'json',
mtype: 'GET',
treeGrid: true,
treeGridModel: 'adjacency',
ExpandColumn : 'key',
// See http://jquery.keicode.com/ui/icons.php
treeIcons: {leaf:'ui-icon-document'},
colNames:['Key','Value'],
colModel :[
{name:'key', index:'key'},
{name:'value', index:'value'}
],
pager: '#pager',
rowNum:10,
rowList:[10,20,30],
sortname: 'key',
sortorder: 'desc',
viewrecords: true,
gridview: true,
caption: 'Tree Grid',
width: 400,
height: 'auto'
});
});
</script>
</head>
<body>
<div style="margin: 20px;">
<button id="export-to-csv">Export to CSV</button>(TAB separator)
<table id="treegrid"></table>
</div>
<div style="margin: 20px;">
<button id="table-to-grid">Tabel-to-grid</button>
<table id="table" border="1">
<tr>
<th>header 1</th>
<th>header 2</th>
</tr>
<tbody>
<tr>
<td>data 1</td>
<td>data 1</td>
</tr>
<tr>
<td>data 2</td>
<td>data 2</td>
</tr>
</tbody>
</table>
</div>
<div style="margin: 20px;">
See <a href="http://code.google.com/p/jquerycsvtotable/">http://code.google.com/p/jquerycsvtotable/</a>
<br/>
CSV Data: <a href="data.csv">data.csv</a>
<div id="CSVSource" style="border: solid 1px;"></div>
<button id="csv-to-table">csv to table</button>
<div id="view-csv"></div>
</div>
<form method="post" action="csvExport.php">
<input type="hidden" name="csvBuffer" id="csvBuffer" value="" />
</form>
</body>
</html> |
Partager