3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AG Grid で実際にテーブル表示してみる

Posted at

前回はAGGridの概要について簡単にまとめてみました。
今回は実際に JavaScript でシンプルに導入してみたいと思います。

サンプルコード

HTML
<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <title>AG Grid Vanilla JS サンプル</title>
  <!-- CDN の読み込み -->
  <script src="https://cdn.jsdelivr.net/npm/ag-grid-community/dist/ag-grid-community.min.js"></script>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ag-grid-community/styles/ag-grid.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ag-grid-community/styles/ag-theme-quartz.css">
</head>
<body>

  <h1>AG Grid JavaScript入門</h1>

  <div id="myGrid" class="ag-theme-quartz" style="height: 300px; width: 600px;"></div>

  <script>
    // 列の定義(どのデータをどの列に見せるか)
    const columnDefs = [
      { field: "name", headerName: "氏名", sortable: true, filter: true },
      { field: "role", headerName: "役職", filter: true },
      { field: "status", headerName: "ステータス" }
    ];

    // 表示するデータ
    const rowData = [
      { name: "田中 太郎", role: "エンジニア", status: "在宅" },
      { name: "佐藤 次郎", role: "デザイナー", status: "出社" },
      { name: "鈴木 花子", role: "マネージャー", status: "会議中" }
    ];

    // グリッドのオプション設定
    const gridOptions = {
      columnDefs: columnDefs,
      rowData: rowData,
    };

    // 初期化:HTML要素と設定を結びつける
    document.addEventListener('DOMContentLoaded', () => {
      const gridDiv = document.querySelector('#myGrid');
      // AG Gridの作成
      agGrid.createGrid(gridDiv, gridOptions);
    });
  </script>
</body>
</html>

・上記コードでできるテーブルイメージ
スクリーンショット 2026-01-29 104540.jpg
導入自体は比較的シンプルにできますね


また columnDefs 内で "sortable: true, filter: true " とすることでソートとフィルターオプションが有効になります。

・項目の順序変更
スクリーンショット 2026-01-29 105235.jpg
・フィルター機能
スクリーンショット 2026-01-29 104555.jpg

以上 JavaScript で AGGrid をシンプルに導入してみました。
JavaScript版のAG Gridは外部ライブラリへの依存が少ないのでお試しにはよさそうですね。

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?