style.html 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <title>设置单元格样式 - 数据表格</title>
  2. <div class="layui-card layadmin-header">
  3. <div class="layui-breadcrumb" lay-filter="breadcrumb">
  4. <a lay-href="">主页</a>
  5. <a><cite>组件</cite></a>
  6. <a><cite>数据表格</cite></a>
  7. <a><cite>设置单元格样式</cite></a>
  8. </div>
  9. </div>
  10. <div class="layui-fluid">
  11. <div class="layui-row layui-col-space15">
  12. <div class="layui-col-md12">
  13. <div class="layui-card">
  14. <div class="layui-card-header">设置单元格样式</div>
  15. <div class="layui-card-body">
  16. <table class="layui-hide" id="test-table-style"></table>
  17. <script type="text/html" id="test-table-usernameTpl">
  18. <a href="/?table-demo-id={{d.id}}" class="layui-table-link" target="_blank">{{ d.username }}</a>
  19. </script>
  20. <script type="text/html" id="test-table-sexTpl">
  21. {{# if(d.sex === '女'){ }}
  22. <span style="color: #F581B1;">{{ d.sex }}</span>
  23. {{# } else { }}
  24. {{ d.sex }}
  25. {{# } }}
  26. </script>
  27. </div>
  28. </div>
  29. </div>
  30. </div>
  31. </div>
  32. <script>
  33. layui.use(['admin', 'table'], function(){
  34. var table = layui.table;
  35. table.render({
  36. elem: '#test-table-style'
  37. ,url: './json/table/user.js'
  38. ,height: 310
  39. ,cols: [[
  40. {field:'id', title:'ID', width:80, sort: true}
  41. ,{field:'username', title:'用户名', width:80, templet: '#usernameTpl'}
  42. ,{field:'sex', title:'性别', width:80, sort: true, templet: '#sexTpl'}
  43. ,{field:'city', title:'城市', width:80}
  44. ,{field:'sign', title:'签名'}
  45. ,{field:'experience', title:'积分', width:80, sort: true, style:'background-color: #eee;'}
  46. ,{field:'score', title:'评分', width:80, sort: true}
  47. ,{field:'classify', title:'职业', width:80, style:'background-color: #009688; color: #fff;'}
  48. ,{field:'wealth', title:'财富', width:135, sort: true}
  49. ]]
  50. ,page: true
  51. ,skin: 'row'
  52. ,even: true
  53. });
  54. });
  55. </script>