【JavaScript】エクセルのようなテーブルを作る。エクセルのデータをコピペするプラグイン(pqgrid、または、ParamQuery)

Sponsored Links

JavaScriptを使用して、エクセルのようなテーブルを作成するプラグイン(pqgrid、または、ParamQuery)のご紹介。

Open Source版と、ライセンス購入版(Pro)があり、Open Source版でもいろいろな機能が備え付けられている。
とくに、エクセルからデータをコピペ、エクセルへデータをコピペは、他のプラグインでは見つけられなかった機能。

ソースのダウンロードは、こちらからできます。

こちらが画面のソース
jqueryのjsとcssを持ってきてからpqgridのjsとcssを読み込む。
テーブルに表示させるデータは、その後の「$(function () { var data = … の部分で定義する。
データ部分に関しては、jsonで定義することもできる

$(function () {
    var data = [
        { rank: 1, company: 'Exxon Mobil', revenues: '339938.0', profits: '36130.0' },
<html>
<head>
<!--jQuery dependencies-->
    <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/themes/base/jquery-ui.css" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>    
    <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"></script>
<!--PQ Grid files-->
    <link rel="stylesheet" href="pqgrid.min.css" />
    <script src="pqgrid.min.js"></script>
<!--PQ Grid Office theme-->
    <link rel="stylesheet" href="themes/office/pqgrid.css" />

<script>
    $(function () {
        var data = [[1, 'Exxon Mobil', '339,938.0', '36,130.0'],
            [2, 'Wal-Mart Stores', '315,654.0', '11,231.0'],
			[3, 'Royal Dutch Shell', '306,731.0', '25,311.0'],
			[4, 'BP', '267,600.0', '22,341.0'],
			[5, 'General Motors', '192,604.0', '-10,567.0'],
			[6, 'Chevron', '189,481.0', '14,099.0'],
			[7, 'DaimlerChrysler', '186,106.3', '3,536.3'],
			[8, 'Toyota Motor', '185,805.0', '12,119.6'],
			[9, 'Ford Motor', '177,210.0', '2,024.0'],
			[10, 'ConocoPhillips', '166,683.0', '13,529.0'],
			[11, 'General Electric', '157,153.0', '16,353.0'],
			[12, 'Total', '152,360.7', '15,250.0'],
			[13, 'ING Group', '138,235.3', '8,958.9'],
			[14, 'Citigroup', '131,045.0', '24,589.0'],
			[15, 'AXA', '129,839.2', '5,186.5'],
			[16, 'Allianz', '121,406.0', '5,442.4'],
			[17, 'Volkswagen', '118,376.6', '1,391.7'],
			[18, 'Fortis', '112,351.4', '4,896.3'],
			[19, 'Crédit Agricole', '110,764.6', '7,434.3'],
			[20, 'American Intl. Group', '108,905.0', '10,477.0']];


        var obj = { width: 700, height: 400, title: "ParamQuery Grid Example",resizable:true,draggable:true };
        obj.colModel = [{ title: "Rank", width: 100, dataType: "integer" },
        { title: "Company", width: 200, dataType: "string" },
        { title: "Revenues ($ millions)", width: 150, dataType: "float", align: "right" },
        { title: "Profits ($ millions)", width: 150, dataType: "float", align: "right"}];
        obj.dataModel = { data: data };
        $("#grid_array").pqGrid(obj);

    });
        
</script>    
</head>
<body>
<div id="grid_array" style="margin:10px;"></div>
</body>

</html>

json版はこちら

<!DOCTYPE html>
<html>
<head>
<!--jQuery dependencies-->
	<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/themes/base/jquery-ui.css" />    
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
	<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"></script>

<!--PQ Grid files-->
    <link rel="stylesheet" href="pqgrid.min.css" />
    <script src="pqgrid.min.js"></script>

<!--jqueryui touch punch for touch devices-->
    <script src="touch-punch/touch-punch.min.js"></script>

<!--PQ Grid Office theme-->
    <link rel='stylesheet' href='themes/office/pqgrid.css' />

<script>
$(function () {
    var data = [
        { rank: 1, company: 'Exxon Mobil', revenues: '339938.0', profits: '36130.0' },
        { rank: 2, company: 'Wal-Mart Stores', revenues: '315654.0', profits: '11231.0' },
        { rank: 3, company: 'Royal Dutch Shell', revenues: '306731.0', profits: '25311.0' },
        { rank: 4, company: 'BP', revenues: '267600.0', profits: '22341.0' },
        { rank: 5, company: 'General Motors', revenues: '192604.0', profits: '-10567.0' },
        { rank: 6, company: 'Chevron', revenues: '189481.0', profits: '14099.0' },
        { rank: 7, company: 'DaimlerChrysler', revenues: '186106.3', profits: '3536.3' },
        { rank: 8, company: 'Toyota Motor', revenues: '185805.0', profits: '12119.6' },
        { rank: 9, company: 'Ford Motor', revenues: '177210.0', profits: '2024.0' },
        { rank: 10, company: 'ConocoPhillips', revenues: '166683.0', profits: '13529.0' },
        { rank: 11, company: 'General Electric', revenues: '157153.0', profits: '16353.0' },
        { rank: 12, company: 'Total', revenues: '152360.7', profits: '15250.0' },
        { rank: 13, company: 'ING Group', revenues: '138235.3', profits: '8958.9' },
        { rank: 14, company: 'Citigroup', revenues: '131045.0', profits: '24589.0' },
        { rank: 15, company: 'AXA', revenues: '129839.2', profits: '5186.5' },
        { rank: 16, company: 'Allianz', revenues: '121406.0', profits: '5442.4' },
        { rank: 17, company: 'Volkswagen', revenues: '118376.6', profits: '1391.7' },
        { rank: 18, company: 'Fortis', revenues: '112351.4', profits: '4896.3' },
        { rank: 19, company: 'Crédit Agricole', revenues: '110764.6', profits: '7434.3' },
        { rank: 20, company: 'American Intl. Group', revenues: '108905.0', profits: '10477.0' }
    ];
    var obj = { 
        numberCell:{resizable:true,title:"#",width:30,minWidth:30},
	editor: {type: 'textbox'},
        title: "ParamQuery Grid with JSON Data",
        resizable:true,
        scrollModel:{autoFit:true, theme:true}
    };
    obj.colModel = [
        { title: "Rank", width: 100, dataType: "integer", dataIndx: "rank" },
        { title: "Company", width: 200, dataType: "string", dataIndx: "company" },
        { title: "Revenues ($ millions)", width: 150, dataType: "float", align: "right", dataIndx: "revenues" },
        { title: "Profits ($ millions)", width: 150, dataType: "float", align: "right", dataIndx: "profits" }
    ];
    obj.dataModel = { data: data };
    $("#grid_json").pqGrid(obj);
});
        
</script>    
</head>
<body>
<div id="grid_json" style="margin:10px;"></div>
</body>

</html>

IT
Sponsored Links
Sponsored Links
Sponsored Links
ようさんチョットでぶ
Copied title and URL
Bitnami