Browse Source

update

pull/1058/head
贤心 2 years ago
parent
commit
2642e573e8
  1. 1
      examples/json/table/demo1.json
  2. 22
      examples/table-test.html
  3. 3
      src/layui.js
  4. 5
      src/modules/code.js
  5. 62
      src/modules/table.js

1
examples/json/table/demo1.json

@ -29,7 +29,6 @@
,"checkin": "106"
,"joinTime": "2016-10-14"
,"LAY_CHECKED": true
,"LAY_DISABLED": true
}, {
"id": "10003"
,"username": "苏轼"

22
examples/table-test.html

@ -76,8 +76,15 @@
<table id="test" lay-filter="test"></table>
<script src="../src/layui.js"></script>
<script src="../src/layui.js" src1="https://cdn.staticfile.org/layui/2.6.13/layui.js"></script>
<script>
(function(off){
if(!off) return;
layui.disuse('table').extend({
table: '{/}//ww:5018/layui/2.6.13/src/modules/table'
});
})();
layui.use(['table', 'dropdown'], function(){
var $ = layui.$;
var table = layui.table;
@ -113,25 +120,27 @@ layui.use(['table', 'dropdown'], function(){
//渲染
window.ins1 = table.render({
elem: '#test'
,height: 500
,height: 520
//,width: 600
,title: '用户数据表'
,url: 'json/table/demo1.json'
//,method: 'post'
,pagebar: '#pagebarDemo' // 分页栏模板
//,lineStyle: 'height: 95px;' // 行样式
,css: [ // 自定义样式
'.layui-table-page{text-align: right;}'
,'.layui-table-pagebar{float: left;}'
].join('')
//,className: '.demo-table-view'
//,size: 'sm'
//,skin: 'line'
//,autoSort: false //是否自动排序。如果否,则由服务端排序
//,loading: false
,totalRow: true
,page: {
,pagebar: '#pagebarDemo' // 分页栏模板
,page: !1 ? false : {
//curr: layui.data('tableCache').curr || 1 // 读取记录中的页码,赋值给起始页
}
,limit: 30
@ -144,6 +153,7 @@ layui.use(['table', 'dropdown'], function(){
//,escape: false
,cols: !1 ? test_cols : [[
{type: 'checkbox', fixed: 'left'}
//,{type: 'numbers', fixed: 'left'}
,{field:'id', title:'ID', width:80, fixed: 'left', unresize: true, sort: true, totalRowText: '合计:'}
,{field:'username', title:'用户名', width:120, edit: 'text', templet: '#usernameTpl'}
,{field:'email', title:'邮箱 <i class="layui-icon layui-icon-email"></i>', hide: 0, width:150, edit: 'text', templet: function(d){
@ -163,7 +173,7 @@ layui.use(['table', 'dropdown'], function(){
,{fixed: 'right', title:'操作', toolbar: '#barDemo', width: 180}
]]
//,autoSort: false // 禁用前端自动排序
//,autoSort: false // 禁用前端自动排序,由服务的完成排序
,initSort11111: { // 初始排序状态
field: 'experience' //排序字段,对应 cols 设定的各字段名
,type: 'desc' //排序方式 asc: 升序、desc: 降序、null: 默认排序

3
src/layui.js vendored

@ -238,7 +238,7 @@
apps = that.isArray(apps) ? apps : [apps];
that.each(apps, function (index, item) {
if (!config.status[item]) {
return error('module ' + item + ' is not exist');
//return error('module ' + item + ' is not exist');
}
delete that[item];
delete modules[item];
@ -246,6 +246,7 @@
delete config.status[item];
delete config.modules[item];
});
return that;
};
//获取节点的 style 属性值

5
src/modules/code.js

@ -26,6 +26,9 @@ layui.define(['util'], function(exports){
layui.each(elems.reverse(), function(index, item){
var othis = $(item);
var html = trim(othis.html());
var about = othis.attr('lay-about') || options.about || (
othis.attr('lay-lang') || options.lang
) || '';
// 转义 HTML 标签
if(othis.attr('lay-encode') || options.encode){
@ -35,7 +38,7 @@ layui.define(['util'], function(exports){
othis.html('<ol class="layui-code-ol"><li>' + html.replace(/[\r\t\n]+/g, '</li><li>') + '</li></ol>')
if(!othis.find('>.layui-code-h3')[0]){
othis.prepend('<h3 class="layui-code-h3">'+ (othis.attr('lay-title')||options.title||'&lt;/&gt;') + '<a href="javascript:;">'+ (othis.attr('lay-lang')||options.lang||'') +'</a>' + '</h3>');
othis.prepend('<h3 class="layui-code-h3">'+ (othis.attr('lay-title')||options.title||'&lt;/&gt;') + '<a href="javascript:;">'+ about +'</a>' + '</h3>');
}
var ol = othis.find('>.layui-code-ol');

62
src/modules/table.js

@ -15,13 +15,13 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
var hint = layui.hint();
var device = layui.device();
//外部接口
// api
var table = {
config: {
config: { // 全局配置项
checkName: 'LAY_CHECKED' // 是否选中状态的字段名
,indexName: 'LAY_TABLE_INDEX' // 初始下标索引名,用于恢复排序
,disabledName: 'LAY_DISABLED'
} //全局配置项
}
,cache: {} // 数据缓存
,index: layui.table ? (layui.table.index + 10000) : 0
@ -98,10 +98,32 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
return obj.text ? $('<div>'+ content +'</div>').text() : content;
}
//字符常量
,MOD_NAME = 'table', ELEM = '.layui-table', THIS = 'layui-this', SHOW = 'layui-show', HIDE = 'layui-hide', HIDE_V = 'layui-hide-v', DISABLED = 'layui-disabled', NONE = 'layui-none'
,ELEM_VIEW = 'layui-table-view', ELEM_TOOL = '.layui-table-tool', ELEM_BOX = '.layui-table-box', ELEM_INIT = '.layui-table-init', ELEM_HEADER = '.layui-table-header', ELEM_BODY = '.layui-table-body', ELEM_MAIN = '.layui-table-main', ELEM_FIXED = '.layui-table-fixed', ELEM_FIXL = '.layui-table-fixed-l', ELEM_FIXR = '.layui-table-fixed-r', ELEM_TOTAL = '.layui-table-total', ELEM_PAGE = '.layui-table-page', ELEM_PAGE_VIEW = '.layui-table-pageview', ELEM_SORT = '.layui-table-sort', ELEM_EDIT = 'layui-table-edit', ELEM_HOVER = 'layui-table-hover'
// 字符
,MOD_NAME = 'table'
,ELEM = '.layui-table'
,THIS = 'layui-this'
,SHOW = 'layui-show'
,HIDE = 'layui-hide'
,HIDE_V = 'layui-hide-v'
,DISABLED = 'layui-disabled'
,NONE = 'layui-none'
,ELEM_VIEW = 'layui-table-view'
,ELEM_TOOL = '.layui-table-tool'
,ELEM_BOX = '.layui-table-box'
,ELEM_INIT = '.layui-table-init'
,ELEM_HEADER = '.layui-table-header'
,ELEM_BODY = '.layui-table-body'
,ELEM_MAIN = '.layui-table-main'
,ELEM_FIXED = '.layui-table-fixed'
,ELEM_FIXL = '.layui-table-fixed-l'
,ELEM_FIXR = '.layui-table-fixed-r'
,ELEM_TOTAL = '.layui-table-total'
,ELEM_PAGE = '.layui-table-page'
,ELEM_PAGE_VIEW = '.layui-table-pageview'
,ELEM_SORT = '.layui-table-sort'
,ELEM_EDIT = 'layui-table-edit'
,ELEM_HOVER = 'layui-table-hover'
// thead 区域模板
,TPL_HEADER = function(options){
@ -326,10 +348,15 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
,hasRender = othis.next('.' + ELEM_VIEW)
//主容器
,reElem = that.elem = $('<div class="layui-form layui-border-box"></div>');
,reElem = that.elem = $('<div></div>');
reElem.addClass(function(){
var arr = [ELEM_VIEW, ELEM_VIEW +'-'+ that.index];
var arr = [
ELEM_VIEW,
ELEM_VIEW +'-'+ that.index,
'layui-form',
'layui-border-box'
];
if(options.className) arr.push(options.className);
return arr.join(' ');
}()).attr({
@ -603,13 +630,13 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
//动态分配列宽
Class.prototype.setColsWidth = function(){
var that = this
,options = that.config
,colNums = 0 //列个数
,autoColNums = 0 //自动列宽的列个数
,autoWidth = 0 //自动列分配的宽度
,countWidth = 0 //所有列总宽度和
,cntrWidth = that.setInit('width');
var that = this;
var options = that.config;
var colNums = 0; // 列个数
var autoColNums = 0; // 自动列宽的列个数
var autoWidth = 0; // 自动列分配的宽度
var countWidth = 0; // 所有列总宽度和
var cntrWidth = that.setInit('width');
// 统计列个数
that.eachCols(function(i, item){
@ -672,7 +699,7 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
var minWidth = item3.minWidth || options.cellMinWidth;
if(item3.colGroup || item3.hide) return;
//给位分配宽的列平均分配宽
// 给未分配宽的列平均分配宽
if(item3.width === 0){
that.getCssRule(options.index +'-'+ item3.key, function(item){
item.style.width = Math.floor(autoWidth >= minWidth ? autoWidth : minWidth) + 'px';
@ -1008,6 +1035,7 @@ layui.define(['laytpl', 'laypage', 'layer', 'form', 'util'], function(exports){
// 因为 page 参数有可能发生变化 先重新铺满
that.fullSize();
// 滚动条补丁
that.haveInit ? that.scrollPatch() : setTimeout(function(){
that.scrollPatch();

Loading…
Cancel
Save