CSV表示
CSV表示
<?xml version="1.0" encoding="utf-8" ?>
<!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-EQUIVE="Content-Type" CONTENT="text/html;charset=utf-8" />
<title>CSV表示</title>
<!-- CSV表示 -->
<script src="../js/prototype.js" type="text/Javascript"></script>
<script src="../js/test8.js" type="text/Javascript"></script>
</head>
<body>
<form id=frm name=frm>
<input id="btnCsvDiplay" type="button" />
<h3 id="csvTitle"></h3>
<div id="csvDisplayArea"></div>
</form>
</body>
</html>
<!--
test8.js
Event.observe( window, 'load', dispCsvHandler );
var csvFilePath = './data/28HYOGO.CSV';
var isDisplay = true;
function dispCsvHandler(){
changeDispNoDisp();
Event.observe( 'btnCsvDiplay', 'click', function (){
if(changeDispNoDisp()){
new Ajax.Request(
csvFilePath,
{
method : 'get',
onComplete : displayCsvData
}
);
}
}
);
}
function changeDispNoDisp(){
isDisplay ? (isDisplay = false) : (isDisplay = true);
if(isDisplay){
$('btnCsvDiplay').value = '郵便番号一覧の非表示';
}
else{
$('btnCsvDiplay').value = 'サーバー上の郵便番号一覧データの表示';
$('csvDisplayArea').innerHTML = '';
}
return isDisplay;
}
function displayCsvData( httpObj ){
var objCSVAttri = {
paramTitleRowNo : 0,
paramHeaderRowNo : 1,
paramReturnCode : 13
};
var csvConvertList = new csvConvertList( objCSVAttri );
$('csvDisplayArea').innerHTML =
csvConvertList.converCsvList( httpObj.responseText );
}
var csvConvertList = Class.create();
csvConvertList.prototype = {
initialize : function( objCSVAttri ){
this.objCSVAttri = objCSVAttri;
}
,
converCsvList : function( csvData ){
var strCsvSepa = ',';
var strReturnCode =
String.fromCharCode( this.objCSVAttri.paramReturnCode );
var csvRowData = csvData.split( strReturnCode );
var strListHtml = '<table cellspacing="0">';
for( this.RowNo = 0; this.RowNo < csvRowData.length; this.RowNo++ ){
this.arrayRowData = csvRowData[this.RowNo].split( strCsvSepa );
if( this.RowNo == this.objCSVAttri.paramTitleRowNo ){
$('csvTitle').innerText = this.arrayRowData[0];
continue;
}
else {
strListHtml +=
this.displayOneData();
}
}
strListHtml += '</table>';
return strListHtml;
}
,
displayOneData : function(){
var strListOneRowHtml = '';
if( this.RowNo == this.objCSVAttri.paramHeaderRowNo ){
strListOneRowHtml += '<tr class="style:background-color : blue;">';
}
else{
strListOneRowHtml += '<tr>';
}
strListOneRowHtml += this.displayColData();
strListOneRowHtml += '</tr>';
return strListOneRowHtml;
}
,
displayColData : function(){
var strNoDataDummy = ' ';
var strColHtml = '';
for(var i = 0; i < this.arrayRowData.length; i++){
strColHtml +=
'<td>' +
(this.arrayRowData[i] == '' ?
strNoDataDummy : this.arrayRowData[i]) +
'</td>';
}
return strColHtml;
}
}
--------------------------------------------------
-->
|
|