首页 > 其他 > 详细

EasyUI表格DataGrid格式化formatter用法

时间:2019-03-07 14:13:59      阅读:173      评论:0      收藏:0      [点我收藏+]

1.通过HTML标签创建数据表格时使用formatter

<!DOCTYPE html>
<html>

    <head>
        <meta charset="utf-8" />
        <title></title>
        <link rel="stylesheet" type="text/css" href="jquery-easyui-1.5.1/themes/default/easyui.css">
        <link rel="stylesheet" type="text/css" href="jquery-easyui-1.5.1/themes/icon.css">
        <script type="text/javascript" src="jquery-easyui-1.5.1/jquery.min.js"></script>
        <script type="text/javascript" src="jquery-easyui-1.5.1/jquery.easyui.min.js"></script>
        <script type="text/javascript" src="jquery-easyui-1.5.1/locale/easyui-lang-zh_CN.js"></script>
        <script type="text/javascript">
            $(document).ready(function(){
                var data = {
                    "rows": [{
                        "stuName": "李斯",
                        "stuAge": 23
                    }, {
                        "stuName": "白起",
                        "stuAge": 25
                    }],
                    "total": 2
                }
                $(#tt).datagrid(loadData,data);
            })                        
            
            //value:字段值;row:行记录数据;index: 行索引
            function formatPrice(value,row,index) {
                if(value>=20){
                    return <span style="color:blue;"> + value + </span>;
                }
            }
        </script>
    </head>

    <body>
        <table id="tt" title="studentInfo" class="easyui-datagrid" style="width:300px;height:250px">
            <thead>
                <tr>
                    <th field="stuName" width="80">学生姓名</th>
                    <th field="stuAge" width="80" formatter="formatPrice">学生年龄</th>
                </tr>
            </thead>
        </table>
    </body>

</html>

2.通过JS创建数据表格时使用formatter

<!DOCTYPE html>
<html>

    <head>
        <meta charset="utf-8" />
        <title></title>
        <link rel="stylesheet" type="text/css" href="jquery-easyui-1.5.1/themes/default/easyui.css">
        <link rel="stylesheet" type="text/css" href="jquery-easyui-1.5.1/themes/icon.css">
        <script type="text/javascript" src="jquery-easyui-1.5.1/jquery.min.js"></script>
        <script type="text/javascript" src="jquery-easyui-1.5.1/jquery.easyui.min.js"></script>
        <script type="text/javascript" src="jquery-easyui-1.5.1/locale/easyui-lang-zh_CN.js"></script>
        <script type="text/javascript">
            $(document).ready(function() {
                var data = {
                    "rows": [{
                        "stuName": "李斯",
                        "stuAge": 23
                    }, {
                        "stuName": "白起",
                        "stuAge": 25
                    }],
                    "total": 2
                }

                $("#tt").datagrid({
                    columns: [
                        [{
                                field: stuName,
                                title: 学生姓名,
                                width: 80
                            },
                            {
                                field: stuAge,
                                title: 学生年龄,
                                width: 80,
                                formatter: function(value, row, index) {
                                    if(value >= 20) {
                                        return <span style="color:blue;"> + value + </span>;
                                    }
                                }
                            }
                        ]
                    ]

                }).datagrid(loadData, data);
            })
        </script>
    </head>

    <body>
        <table id="tt" title="studentInfo" style="width:300px;height:250px"></table>
    </body>

</html>

 

EasyUI表格DataGrid格式化formatter用法

原文:https://www.cnblogs.com/fengfuwanliu/p/10489157.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!