JS table源码


一、JS源码

1.jquery-table

在这里插入图片描述

代码如下):

<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title>组网专线.襄阳电信</title>
		<script src="js/jquery-3.3.1.min.js"></script>
		<script src="js/tableExport.min.js"></script>
		<script type="text/javascript">
			$(function() {
				//显示日期
				var now;
				now = new Date();
				$(".nowTime").html(now.getFullYear() + "年" + (now.getMonth() + 1) + "月" + now.getDate() + "日" + now.getHours() +
					"时");

				//获取单位名称
				$.get("http://:8080/zwzx/DbService/getCustName",
					function(data) {
						$.each(data, function(index, item) {
							s = "<option>" + item.CUST_NAME + " </option>";
							$("#cust_name").append(s);
						})
					}, "json")

				//增加地区名称
				s = "<option>" + "襄阳市樊城区" + " </option>" +
					"<option>" + "襄阳市樊西区" + " </option>" +
					"<option>" + "襄阳市高新区" + " </option>" +
					"<option>" + "襄阳市襄城区" + " </option>" +
					"<option>" + "襄阳市襄州区" + " </option>" +
					"<option>" + "襄阳市老河口" + " </option>" +
					"<option>" + "襄阳市枣阳市" + " </option>" +
					"<option>" + "襄阳市宜城市" + " </option>" +
					"<option>" + "襄阳市谷城县" + " </option>" +
					"<option>" + "襄阳市南漳县" + " </option>" +
					"<option>" + "襄阳市保康县" + " </option>"
				$("#region_name").append(s);

				var indexSum = 0; //数量
			
				var OperState = ""; //ONU运行状态
				var LastOffTime = "" //ONU最近一次脱网时间
				var Length = "" //光纤长度
				var Temperature = "" //ONU温度
				var RxPower = "" //接收光功率
				var TxPower = "" //发送光功率
				var PTxPower = "" //OLT发送光功率
				var PRxPower = "" //OLT接收光功率

				//下拉框选择执行的事件 
				//客户名称选择
				$("#cust_name").change(function() {
					var custOption = $("#cust_name option:selected").val(); //获取下拉框值

					for (var i = 0; i < indexSum; i++) {
						var custNameTd = $("#tbody tr:eq(" + i + ") td:eq(1)").html(); //获取table中的值

						if (custOption == "---------客户名称---------") {
							$("#tbody tr:eq(" + i + ")").show();
						} else if (custNameTd == custOption) {
							$("#tbody tr:eq(" + i + ")").show();
						} else {
							$("#tbody tr:eq(" + i + ")").hide();
						}
					}
				});
		
				//获取所有Pon数据
				$.get("http://:8080/zwzx/api/v1/get/pons",
					function(data) {
						$.each(data.data, function(index, item) {
							s = "<tr><td>" + (index + 1) + "</td><td>" + item.cust_name + "</td><td>" + item.useraddress.substring(0, 6) +
								"</td><td>" +item.sn + "</td><td>" + item.factory +"</td><td>" + OperState + "</td><td>" + LastOffTime + "</td><td>" +
								Length + "</td><td>" + Temperature + "</td><td>" + TxPower + "</td><td>" +
								RxPower + "</td><td>" + PTxPower + "</td><td>" + PRxPower + "</td><td>" +
								item.acc_num + "</td><td>" + item.useraddress + "</td><td>" + item.region_name +
								"</td></tr>";
							$("#tbody").append(s);

							indexSum = index + 1; //赋值总数量;

							//由SN获取状态
							var url = "http://:8080/zwzx/api/v1/get/onustate/sn/?sn=" + item.sn + "";
							$.getJSON(url,
								function(dataSn, status) {

									if (dataSn.resultCode == 'success') {
										OperState = dataSn.data.operState;
										LastOffTime = dataSn.data.lastOffTime;
										Length = dataSn.data.length;
										Temperature = dataSn.data.temperature;
										TxPower = dataSn.data.txPower;
										RxPower = dataSn.data.rxPower;
										PTxPower = dataSn.data.ptxPower;
										PRxPower = dataSn.data.prxPower;
										//console.log(OperState+item.region_name+item.useraddress)
									} else {
										OperState = dataSn.resultCode;
									}

									//非正常状态显示红色
									if (OperState != "UP") {
										$("#tbody tr:eq(" + index + ") ").css({
											color: "red"
										});
									}

									$("#tbody tr:eq(" + index + ") td:eq(5)").html(OperState);
									$("#tbody tr:eq(" + index + ") td:eq(6)").html(LastOffTime);
									$("#tbody tr:eq(" + index + ") td:eq(7)").html(Length);
									$("#tbody tr:eq(" + index + ") td:eq(8)").html(Temperature);
									$("#tbody tr:eq(" + index + ") td:eq(9)").html(TxPower);
									$("#tbody tr:eq(" + index + ") td:eq(10)").html(RxPower);
									$("#tbody tr:eq(" + index + ") td:eq(11)").html(PTxPower);
									$("#tbody tr:eq(" + index + ") td:eq(12)").html(PRxPower);

								}, "json");
						})

					}, "json");
			});
		</script>
	</head>

	<body>
		<h2>组网专线监测平台</h2>
		<h3>&nbsp;&nbsp;

			<button onClick="$('#fl-table').tableExport({ type: 'excel', escape: 'false', fileName: '组网专线'})">导出Excel</button>
			<span class="nowTime">当前时间</span>
			<a class="text-success" style="color:#F00">
				(up:正常状态;Power-Off:断电状态;Other:未注册;LOS:光纤线路问题;空白:网管无数据)
			</a>
		</h3>
		<div class="table-wrapper">
			<table class="fl-table" id="fl-table">
				<thead>
					<tr>
						<th>序号</th>
						<th><select id="cust_name">
								<option>---------客户名称---------</option>
							</select></th>
						<!-- <th><select id="region_name">
								<option>------区域------</option>
							</select></th> -->
						<th>区域</th>
						<th>SN号</th>
						<th>OLT厂家</th>
						
						<th>ONU状态</th>
						<th>最近一次脱网时间</th>
						<th>光纤长度(km)</th>
						<th>温度()</th>
						<th>发送光功率(dBm)</th>
						<th>接收光功率(dBm)</th>
						<th>OLT发送光功率(dBm)</th>
						<th>OLT接收光功率(dBm)</th>

						<th>接入号码</th>
						<th>安装地址</th>
						<th>地区</th>
					</tr>
				</thead>
				<tbody id="tbody">
					<!-- 			    <tr>
                    <td id="cust_name">cust_name</td>
                </tr>  -->
				<tbody>
			</table>
		</div>

	</body>

	<style>
		* {
			box-sizing: border-box;
			-webkit-box-sizing: border-box;
			-moz-box-sizing: border-box;
		}

		body {
			font-family: Helvetica;
			-webkit-font-smoothing: antialiased;
			background: white;
		}

		h2 {
			text-align: center;
			font-size: 36px;
			text-transform: uppercase;
			letter-spacing: 1px;
			color: black;
			padding: 5px 0;
		}


		h3 {
			font-size: 16px;
			margin-left: 12px;

			color: dodgerblue;
			;
			padding-left: 50px;
		}

		/* Table Styles */

		.table-wrapper {
			margin: 10px 70px 70px;
			box-shadow: 0px 35px 50px rgba(0, 0, 0, 0.2);
		}

		.fl-table {
			border-radius: 5px;
			font-size: 12px;
			font-weight: normal;
			border: none;
			border-collapse: collapse;
			width: 100%;
			max-width: 100%;
			white-space: nowrap;
			background-color: white;
		}

		.fl-table td,
		.fl-table th,
		.fl-table select {
			text-align: center;
			padding: 8px;
		}

		.fl-table td {
			border-right: 1px solid #f8f8f8;
			font-size: 12px;
		}

		.fl-table thead th {
			color: #ffffff;
			background: #4FC3A1;
		}


		.fl-table thead th:nth-child(odd) {
			color: #ffffff;
			background: #324960;
		}

		.fl-table tr:nth-child(even) {
			background: #F8F8F8;
		}

		/* Responsive */

		@media (max-width: 767px) {
			.fl-table {
				display: block;
				width: 100%;
			}

			.table-wrapper:before {
				content: "Scroll horizontally >";
				display: block;
				text-align: right;
				font-size: 11px;
				color: white;
				padding: 0 0 10px;
			}

			.fl-table thead,
			.fl-table tbody,
			.fl-table thead th {
				display: block;
			}

			.fl-table thead th:last-child {
				border-bottom: none;
			}

			.fl-table thead {
				float: left;
			}

			.fl-table tbody {
				width: auto;
				position: relative;
				overflow-x: auto;
			}

			.fl-table td,
			.fl-table th {
				padding: 20px .625em .625em .625em;
				height: 60px;
				vertical-align: middle;
				box-sizing: border-box;
				overflow-x: hidden;
				overflow-y: auto;
				width: 120px;
				font-size: 13px;
				text-overflow: ellipsis;
			}

			.fl-table thead th {
				text-align: left;
				border-bottom: 1px solid #f7f7f9;
			}

			.fl-table tbody tr {
				display: table-cell;
			}

			.fl-table tbody tr:nth-child(odd) {
				background: none;
			}

			.fl-table tr:nth-child(even) {
				background: transparent;
			}

			.fl-table tr td:nth-child(odd) {
				background: #F8F8F8;
				border-right: 1px solid #E6E4E4;
			}

			.fl-table tr td:nth-child(even) {
				border-right: 1px solid #E6E4E4;
			}

			.fl-table tbody td {
				display: block;
				text-align: center;
			}

		}
	</style>

</html>

在这里插入图片描述

<table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>


<script>
    {#var tableData=new Array(); // 用于存放表格数据#}
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;
         // 加载提示
        var loadingMsg = layer.msg('数据请求中...', {icon: 16,   shade: [0.5],   scrollbar: false,   time: 0});

        var tableData = []; //存放数据
        //获取所有Pon数据
        $.get("http://:8080/zwzx/api/v1/get/pons/custid/?custid=39008781920",
            function (data) {

                $.each(data.data, function (index, item) {

                    tableData.push({
                        cust_name: item.cust_name,
                        sn: item.sn,
                        factory: item.factory,
                        acc_num: item.acc_num,
                        useraddress: item.useraddress,
                        region_name: item.region_name
                    });

                    var url = "http://:8080/zwzx/api/v1/get/onustate/sn/?sn=" + item.sn + "";

                    $.getJSON(url,
                        function (dataSn, status) {

                            for (var i = 0, tableDataLen = tableData.length; i < tableDataLen; i++) {

                                    if (tableData[i].sn === item.sn ) {
                                        tableData[i].operState=dataSn.data.operState;
                                        tableData[i].lastOffTime=dataSn.data.lastOffTime;
                                        tableData[i].length=dataSn.data.length+"(km)";
                                        tableData[i].temperature=dataSn.data.temperature+"(℃)";
                                        tableData[i].txPower =dataSn.data.txPower+"(dBm)";
                                        tableData[i].rxPower =dataSn.data.rxPower+"(dBm)";
                                        tableData[i].ptxPower =dataSn.data.ptxPower+"(dBm)";
                                        tableData[i].prxPower =dataSn.data.prxPower+"(dBm)";
                                     }
                            }

                            setTimeout(function () {
                                table.render({
                                    elem: '#currentTableId',
                                    toolbar: '#toolbarDemo',
                                    cellMinWidth: 80,
                                    defaultToolbar: ['filter', 'exports', 'print', {
                                        title: '提示',
                                        layEvent: 'LAYTABLE_TIPS',
                                        icon: 'layui-icon-tips'
                                    }],
                                    cols: [[
                                        {type: 'numbers', sort: true, fixed: 'left'},
                                        {field: 'cust_name', title: '客户名称',  width:160,align: 'left', sort: true, fixed: 'left'},
                                        {field: 'sn', title: 'SN号', width:110, fixed: 'left', sort: true},
                                        {field: 'factory', title: 'OLT',width: 80,align: 'left',sort: true,fixed: 'left',
                                            templet: function (d) {
                                                if (d.factory == "HW") {
                                                    dev = '华为'
                                                } else if (d.factory == "ZX") {
                                                    dev = '中兴'
                                                } else if (d.factory == "FH") {
                                                    dev = '烽火'
                                                }
                                                return dev;
                                            }
                                        },
                                        {field: 'operState',title: 'ONU状态',width: 110,align: 'left',fixed: 'left',
                                          style:'background-color: #eee;',sort: true,
                                            templet: function (d) {
                                                if (d.operState == "UP") {
                                                    res = '正常'
                                                } else if (d.operState == "Power-Off") {
                                                    res = '<span style="color: #c00;"> 断电状态</span>'

                                                } else if (d.operState == "Other") {
                                                    res = '<span style="color: #c00;"> 未注册</span>'

                                                } else if (d.operState == "LOS") {
                                                    res = '<span style="color: #c00;"> 线路问题</span>'

                                                } else {
                                                    res = '<span style="color: #c00;"> 网管无数</span>'
                                                }
                                                return res;
                                            }
                                        },
                                        {field: 'lastOffTime', title: '最近一次脱网时间', width:160,align: 'left', sort: true},
                                        {field: 'length', title: '光纤长度',  width:110,align: 'left', sort: true},
                                        {field: 'temperature', title: '温度',  width:90,align: 'left'},
                                        {field: 'txPower', title: '发送光功率',  width:110,align: 'left'},
                                        {field: 'rxPower', title: '接收光功率',  width:110,align: 'left'},
                                        {field: 'ptxPower', title: 'OLT发送光功率', width:130, align: 'left'},
                                        {field: 'prxPower', title: 'OLT接收光功率',  width:130,align: 'left'},

                                        {field: 'useraddress', title: '安装地址', width:360, align: 'left'},
                                        {field: 'acc_num', title: '接入号码', width:110, align: 'left', fixed: 'right',style:'background-color: #eee;', sort: true},
                                        {field: 'region_name', title: '地区', width:80, align: 'left',  fixed: 'right',sort: true},

                                    ]],
                                    data: tableData,
                                    initSort: {
                                        field: 'operState' ,//排序字段,对应 cols 设定的各字段名
                                        type: 'asc' //排序方式  asc: 升序、desc: 降序、null: 默认排序
                                    },
                                    page: true, //是否显示分页
                                    limits: [10,20,50,100,200],
                                    limit: 10, //每页默认显示的数量
                                    even: true,
                                    done: function (res, curr, count) {
                                        /** 数据渲染完的回调 */
                                        // 关闭提示层
                                        layer.close(loadingMsg);
                                     }
                                    //skin: 'line' //表格风格
                                });

                            }, 10);

                        }, "json");

                }, "json");
            }
        );



    })
</script>

2.layui-table

在这里插入图片描述

代码如下:

<table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter">

<script src="/static/layui-v2.6.1/layui/layui.js" charset="utf-8"></script>

<script>
    {#var tableData=new Array(); // 用于存放表格数据#}
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;
        var tableData = []; //存放数据

        //获取所有Pon数据
        $.get("http://:8080/zwzx/api/v1/get/pons/custid/?custid=39001632062",
            function (data) {
                $.each(data.data, function (index, item) {
                    tableData.push({
                        cust_name: item.cust_name, sn: item.sn, factory: item.factory,
                        acc_num: item.acc_num, useraddress: item.useraddress, region_name: item.region_name
                    });
                }, "json");

                table.render({
                    elem: '#currentTableId',
                    cols: [[
                        {type: 'numbers', sort: true},
                        {field: 'cust_name', title: '客户名称', width: 160, align: 'left', sort: true},
                        {field: 'sn', title: 'SN号'},
                        {field: 'factory', title: 'OLT厂家', align: 'left',sort: true},

                        {field: 'operState', title: 'ONU状态', align: 'left'},
                        {field: 'lastOffTime', title: '最近一次脱网时间', align: 'left',sort: true},
                        {field: 'length', title: '光纤长度(km)', align: 'left', sort: true},
                        {field: 'temperature', title: '温度(℃)', align: 'left',},
                        {field: 'txPower', title: '发送光功率(dBm)', align: 'left', sort: true},
                        {field: 'rxPower', title: '接收光功率(dBm)', align: 'left', sort: true},
                        {field: 'ptxPower', title: 'OLT发送光功率(dBm)', align: 'left', sort: true},
                        {field: 'prxPower', title: 'OLT接收光功率(dBm)', align: 'left'},

                        {field: 'acc_num', title: '接入号码', align: 'left', sort: true},
                        {field: 'useraddress', title: '安装地址', align: 'left', sort: true},
                        {field: 'region_name', title: '地区',align: 'left'}
                    ]],
                    data: tableData,
                    page: true, //是否显示分页
                    limits: [5, 10, 20, 50],
                    limit: 10, //每页默认显示的数量
                    //skin: 'line' //表格风格
                });
            }
        )
    });
</script>

table.render({
            elem: '#currentTableId',
            url: 'http://:8080/zwzx/api/v1/get/pons/custid/?custid=39001632062',
            {#url: 'http://:8080/zwzx/api/v1/get/onustate/sn/?sn=XY1412977',#}
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {type: "checkbox", width: 50},
                {type: 'numbers', sort: true},
                {field: 'cust_name', width: 80, title: '客户名称', sort: true},
                {field: 'sn', width: 80, title: 'SN号'},
                {field: 'factory', width: 80, title: 'OLT厂家', sort: true},

                {field: 'operState', title: 'ONU状态', minWidth: 150},
                {field: 'lastOffTime', width: 80, title: '最近一次脱网时间', sort: true},
                {field: 'length', width: 80, title: '光纤长度(km)', sort: true},
                {field: 'temperature', width: 80, title: '温度(℃)'},
                {field: 'txPower', width: 135, title: '发送光功率(dBm)', sort: true},
                {field: 'rxPower', width: 80, title: '接收光功率(dBm)', sort: true},
                {field: 'ptxPower', width: 80, title: 'OLT发送光功率(dBm)', sort: true},
                {field: 'prxPower', width: 80, title: 'OLT接收光功率(dBm)'},

                {field: 'acc_num', width: 135, title: '接入号码', sort: true},
                {field: 'useraddress', width: 80, title: '安装地址', sort: true},
                {field: 'region_name', width: 80, title: '地区'},
                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
            ]],

            response: {
                statusName: 'resultCode' //规定数据状态的字段名称,默认:code
                , statusCode: 'success' //规定成功的状态码,默认:0
                , msgName: 'msg' //规定状态信息的字段名称,默认:msg
                , dataName: 'data' //规定数据列表的字段名称,默认:data
                , countName: 'count' //规定数据总数的字段名称,默认:count
            },
            page: true,
            limits: [5, 10, 15, 20, 25, 50, 100],
            limit: 5,
            skin: 'line'
        });
<script>
    {#var tableData=new Array(); // 用于存放表格数据#}
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        var OperState = "" //ONU运行状态
        var tableData = []; //存放数据

        //获取所有Pon数据
        $.get("http://:8080/zwzx/api/v1/get/pons/custid/?custid=39001632062",
            function (data) {

                $.each(data.data, function (index, item) {

                    var url = "http://:8080/zwzx/api/v1/get/onustate/sn/?sn=" + item.sn + "";

                    $.getJSON(url,
                        function (dataSn, status) {
                            if (dataSn.resultCode == 'success') {
                                tableData.push({
                                    cust_name: item.cust_name,
                                    sn: item.sn,
                                    factory: item.factory,
                                    operState: dataSn.data.operState,
                                    lastOffTime: dataSn.data.lastOffTime,
                                    length: dataSn.data.length,
                                    temperature: dataSn.data.temperature,
                                    txPower: dataSn.data.txPower,
                                    rxPower: dataSn.data.rxPower,
                                    ptxPower: dataSn.data.ptxPower,
                                    prxPower: dataSn.data.prxPower,
                                    acc_num: item.acc_num,
                                    useraddress: item.useraddress,
                                    region_name: item.region_name
                                });
                            } else {
                                OperState = dataSn.resultCode;
                            }
                            i++;
                        }, "json");

                        setTimeout(function () {
                                table.render({
                                    elem: '#currentTableId',
                                    toolbar: '#toolbarDemo',
                                    defaultToolbar: ['filter', 'exports', 'print', {
                                        title: '提示',
                                        layEvent: 'LAYTABLE_TIPS',
                                        icon: 'layui-icon-tips'
                                    }],
                                    cols: [[
                                        {type: 'numbers', sort: true},
                                        {field: 'cust_name', title: '客户名称', align: 'left', sort: true},
                                        {field: 'sn', title: 'SN号', templet: '#sn'},
                                        {field: 'factory', title: 'OLT厂家', align: 'left', unresize: true, sort: true},

                                        {field: 'operState', title: 'ONU状态', align: 'left'},
                                        {field: 'lastOffTime', title: '最近一次脱网时间', align: 'left', sort: true},
                                        {field: 'length', title: '光纤长度(km)', align: 'left', sort: true},
                                        {field: 'temperature', title: '温度(℃)', align: 'left',},
                                        {field: 'txPower', title: '发送光功率(dBm)', align: 'left', sort: true},
                                        {field: 'rxPower', title: '接收光功率(dBm)', align: 'left', sort: true},
                                        {field: 'ptxPower', title: 'OLT发送光功率(dBm)', align: 'left', sort: true},
                                        {field: 'prxPower', title: 'OLT接收光功率(dBm)', align: 'left'},

                                        {field: 'acc_num', title: '接入号码', align: 'left', sort: true},
                                        {field: 'useraddress', title: '安装地址', align: 'left', sort: true},
                                        {field: 'region_name', title: '地区', align: 'left'}
                                    ]],
                                    data: tableData,
                                    page: true, //是否显示分页
                                    limits: [10, 20, 50, 100],
                                    limit: 10, //每页默认显示的数量
                                    even: true
                                    //skin: 'line' //表格风格
                                });
                        }, 6000);

                }, "json");
            }
        );
</script>

2.layui-table-编辑

在这里插入图片描述

layer.prompt({
        //表单元素类型 0=文本框 1=密码框 2=文本域
        formType:0,
        value:""   //初始时的值,默认空字符
    },function (value,index) {
        obj.update({
            cust_name:value
        });
        layer.close(index);
    });

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值