在 jQuery EasyUI 的 DataGrid 中,你可以通过扩展行显示细节(Row Detail)来实现在每行下方显示更多的信息。以下是一个简单的例子,演示如何在 DataGrid 中扩展行显示细节:
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>jQuery EasyUI 扩展行显示细节示例</title>
    <!-- 引入 jQuery 库 -->
    <script type="text/javascript" src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
    <!-- 引入 EasyUI 样式和脚本文件 -->
    <link rel="stylesheet" type="text/css" href="https://www.jeasyui.com/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="https://www.jeasyui.com/easyui/themes/icon.css">
    <script type="text/javascript" src="https://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>
</head>
<body>

    <!-- 创建 EasyUI Datagrid -->
    <table id="datagrid" class="easyui-datagrid" style="width:100%;height:300px"
           url="your_data_url"
           pagination="true"
           rownumbers="true"
           fitColumns="true">
        <thead>
            <tr>
                <!-- 列定义 -->
                <th field="name" width="100">名称</th>
                <th field="price" width="100" align="right">价格</th>
                <th field="quantity" width="100" align="right">数量</th>
            </tr>
        </thead>
    </table>

    <!-- JavaScript 部分 -->
    <script type="text/javascript">
        // JavaScript 代码

        $(function(){
            $('#datagrid').datagrid({
                // 其他配置...

                // 扩展行显示细节
                view: detailview,
                detailFormatter: function(index, row){
                    // 在这里实现扩展行显示细节的内容
                    return '<div style="padding:2px"><b>详细信息:</b> ' + row.description + '</div>';
                },
                onExpandRow: function(index, row){
                    // 在这里处理展开行时的逻辑
                }
            });
        });
    </script>

</body>
</html>

在上述代码中,通过设置 view 为 detailview,并配置 detailFormatter 函数来定义扩展行显示细节的内容。在 onExpandRow 函数中,你可以处理展开行时的逻辑。

确保替换 "your_data_url" 为实际数据源的 URL,并根据你的数据模型修改列的名称和数量。在这个例子中,我使用了一个名为 description 的字段作为详细信息的内容,你可以根据实际需求修改为其他字段。


转载请注明出处:http://www.zyzy.cn/article/detail/13124/jQuery EasyUI