layui table动态表格代码
layui.use('table', function(){
var table = layui.table;
//渲染
window.ins1 = table.render({
elem : '#test'
,height : 520
,title : '表格名称'
,url : 你的接口名称
,autoSort : false
,loading : true
,totalRow : true
,limit : 10
,toolbar : '#toolbarDemo'
,cols : [
[
{field:'img' , title:'图片预览' , width:260,templet:function (d) {
return '<img src='+d.img+' />';
}}
,{field:'id' , title:'ID' , width:200, unresize: true}
,{field:'remark' , title:'备注' , width:500,edit: 'text'}
,{field:'href' , title:'图片链接' , width:400,edit: 'text'}
,{title:'操作' , toolbar: '#barDemo', width:150}
]
]
,id : 'test'
,page : false
});
});
使用上面的配置之后你会发现图片显示不全,图片大小受表格高度限制,所以在你的页面添加如下样式
更改layui样式使图片显示
<style type="text/css">
.layui-table-cell{
height:auto!important;
white-space:normal;
}
</style>
layui表格
<table class="layui-hide" id="test" lay-filter="test"></table>