天天看點

Layui<table>資料表格之外的資料渲染

有些時間使用layui渲染表格資料,可能不僅需要渲染table,也有可能需要做各種統計或者其他操作,這個時候值就不友善渲染。

找了很久解決辦法,終的大悟,其實很簡單,隻需要引用layui的parseData 插件就可以實作,下面有例子!

var tableIns = table.render({
		elem : '#adminList',
		url : '',
		cellMinWidth : 95,
		page : true,
		method : 'post',
		height : "full-175",
		loading : true,
		id : "adminListTable",
		parseData : function(res) { //res 即為原始傳回的資料
			$(".sum").val(res.data.sum);
			return {
				"code" : res.code, //解析接口狀态
				"msg" : res.msg, //解析提示文本
				"count" : res.count, //解析資料長度
				"data" : res.data.listData //解析資料清單
			};
		},
		cols : [ [
				{type : "checkbox",fixed : "left",width : 50},
				{field : 'title',title : '房源标題',minWidth : 100,align : "center"},
				{field : 'quota',title : '期望金額(萬元)',minWidth : 100,align : "center"},
				{field : 'name',title : '用款人姓名',minWidth : 100,align : "center"},
				{field : 'nikeName',title : '用款人昵稱',minWidth : 100,align : "center"},
				{field : 'count',title : '房源投标量',minWidth : 100,align : "center"},
				{field : 'cost',title : '房源總收入(元)',minWidth : 100,align : "center"},
				{field : 'operationTime',title : '釋出時間',minWidth : 165,align : "center"},
				{field : 'status',title : '房源狀态',align : 'center',width : 100,
					templet : function(d) {
						var js = d.status;
						if (js == 0) {
							return "正常";
						} else if (js == 1) {
							return "結束";
						}
					}
				},
				{title : '操作',minWidth : 175,templet : '#adminListBar',fixed : "right",align : "center"}
			] ]
	});
           
Layui<table>資料表格之外的資料渲染

剛進入時

Layui<table>資料表格之外的資料渲染

條件過濾後

注意事項:該插件為 layui 2.4.0 開始新增!抓緊去更新嘗試把!layui官網