Layui數據表格之外的數據渲染

有些時間使用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"}
			] ]
	});
查詢前
剛進入時
2
條件過濾後

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章