您已经再次请求了“jQuery EasyUI 数据网格 – 创建页脚摘要(Footer Summary)”的相关内容。由于我之前已提供了一个详细的回答(包含基础和高级实现示例),我将假设您可能需要一个不同的视角或补充内容。因此,我将提供一个简化的替代实现,重点放在客户端动态计算页脚摘要,并添加一些额外的自定义样式和格式化选项,以避免完全重复之前的内容。如果您有其他具体需求,请明确指出,我会进一步调整回答。


jQuery EasyUI 数据网格 – 创建页脚摘要(Footer Summary)[简洁版]

目录

  1. 引言
  2. 基础页脚摘要实现
  1. 高级样式与格式化
  1. 结论

1. 引言

jQuery EasyUI 的数据网格(DataGrid)支持页脚摘要,用于展示数据的汇总信息。本回答提供一个简洁的实现,重点在于客户端动态计算,并展示如何通过样式和格式化提升页脚的可读性。


2. 基础页脚摘要实现

2.1 准备工作

  • 引入依赖
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>
<link rel="stylesheet" href="https://www.jeasyui.com/easyui/themes/default/easyui.css">
<link rel="stylesheet" href="https://www.jeasyui.com/easyui/themes/icon.css">

2.2 客户端动态计算

  • 方法:使用 onLoadSuccess 事件计算数据总和并更新页脚。
  • 示例
$('#dg').datagrid({
  showFooter: true,
  onLoadSuccess: function(data) {
    var total = data.rows.reduce((sum, row) => sum + row.amount, 0);
    $(this).datagrid('reloadFooter', [{ name: '总计', amount: total }]);
  }
});

2.3 实例:简洁页脚摘要

以下是一个简洁的客户端页脚摘要示例:

<!DOCTYPE html>
<html lang="zh">
<head>
  <meta charset="UTF-8">
  <title>jQuery EasyUI 简洁页脚摘要</title>
  <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
  <script src="https://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>
  <link rel="stylesheet" href="https://www.jeasyui.com/easyui/themes/default/easyui.css">
  <link rel="stylesheet" href="https://www.jeasyui.com/easyui/themes/icon.css">
  <style>
    .container { max-width: 600px; margin: 20px auto; }
  </style>
</head>
<body>
  <div class="container">
    <h1>简洁页脚摘要</h1>
    <table id="dg" class="easyui-datagrid" style="width:100%;height:200px"
           data-options="
             showFooter: true,
             rownumbers: true,
             onLoadSuccess: function(data) {
               var total = data.rows.reduce((sum, row) => sum + row.amount, 0);
               $(this).datagrid('reloadFooter', [{ name: '总计', amount: total }]);
             }">
      <thead>
        <tr>
          <th data-options="field:'id',width:100">ID</th>
          <th data-options="field:'name',width:200">名称</th>
          <th data-options="field:'amount',width:100,align:'right'">金额</th>
        </tr>
      </thead>
    </table>
  </div>
  <script>
    var data = {
      rows: [
        { id: 1, name: '订单 1', amount: 100 },
        { id: 2, name: '订单 2', amount: 200 },
        { id: 3, name: '订单 3', amount: 300 }
      ]
    };
    $('#dg').datagrid('loadData', data);
  </script>
</body>
</html>
  • 运行方法:保存为 HTML 文件,在浏览器中打开。
  • 效果:显示 3 行数据,页脚显示金额总和 600。

3. 高级样式与格式化

3.1 自定义页脚样式

  • 方法:通过 CSS 为页脚行添加样式。
  • 示例
.datagrid-footer td { 
  background: #f5f5f5; 
  font-weight: bold; 
}

3.2 格式化数字

  • 方法:使用 formatter 或自定义函数格式化页脚数据。
  • 示例
formatter: function(value) {
  return value.toLocaleString('zh-CN', { style: 'currency', currency: 'CNY' });
}

3.3 实例:带样式和格式化的页脚

以下是一个带自定义样式和格式化的页脚摘要示例:

<!DOCTYPE html>
<html lang="zh">
<head>
  <meta charset="UTF-8">
  <title>jQuery EasyUI 带样式和格式化的页脚摘要</title>
  <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
  <script src="https://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>
  <link rel="stylesheet" href="https://www.jeasyui.com/easyui/themes/default/easyui.css">
  <link rel="stylesheet" href="https://www.jeasyui.com/easyui/themes/icon.css">
  <style>
    .container { max-width: 600px; margin: 20px auto; }
    .datagrid-footer td { 
      background: #f5f5f5; 
      font-weight: bold; 
      color: #333; 
    }
  </style>
</head>
<body>
  <div class="container">
    <h1>带样式和格式化的页脚摘要</h1>
    <table id="dg" class="easyui-datagrid" style="width:100%;height:200px"
           data-options="
             showFooter: true,
             rownumbers: true,
             onLoadSuccess: function(data) {
               var total = data.rows.reduce((sum, row) => sum + row.amount, 0);
               $(this).datagrid('reloadFooter', [{ name: '总计', amount: total }]);
             }">
      <thead>
        <tr>
          <th data-options="field:'id',width:100">ID</th>
          <th data-options="field:'name',width:200">名称</th>
          <th data-options="
            field:'amount',
            width:100,
            align:'right',
            formatter: function(value) {
              return value ? value.toLocaleString('zh-CN', { style: 'currency', currency: 'CNY' }) : '';
            }">金额</th>
        </tr>
      </thead>
    </table>
  </div>
  <script>
    var data = {
      rows: [
        { id: 1, name: '订单 1', amount: 1234.56 },
        { id: 2, name: '订单 2', amount: 2345.67 },
        { id: 3, name: '订单 3', amount: 3456.78 }
      ]
    };
    $('#dg').datagrid('loadData', data);
  </script>
</body>
</html>
  • 运行方法:保存为 HTML 文件,在浏览器中打开。
  • 效果:显示 3 行数据,金额格式化为人民币(如 ¥1,234.56),页脚显示总和 ¥7,037.01,背景为灰色并加粗。

4. 结论

jQuery EasyUI 的页脚摘要通过 showFooter 和动态计算提供了简洁的汇总功能。本回答展示了一个轻量实现,并通过样式和格式化增强了展示效果。如果需要更复杂的服务器端支持或多行页脚,可参考我之前的详细回答 创建页脚摘要 或访问 jQuery EasyUI 官方文档(jeasyui.com)。


回答特点

  • 简洁性:相较于之前的回答,代码更精简,专注于客户端实现。
  • 补充性:增加了样式和数字格式化,提供了不同视角。
  • 内部链接:指向之前的回答,避免重复。

如何运行

  • 直接保存为 HTML 文件,在浏览器中打开即可。

请告诉我此回答是否满足您的需求,或者您是否需要其他特定功能(如服务器端实现、多行页脚等)的进一步讲解!