forked from fanruan/fineui
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
278 lines
8.3 KiB
278 lines
8.3 KiB
/** |
|
* 分页表格 |
|
* |
|
* Created by GUY on 2016/2/15. |
|
* @class BI.PageTable |
|
* @extends BI.Widget |
|
*/ |
|
BI.PageTable = BI.inherit(BI.Widget, { |
|
|
|
_const: { |
|
scrollWidth: 18, |
|
minScrollWidth: 100 |
|
}, |
|
|
|
_defaultConfig: function () { |
|
return BI.extend(BI.PageTable.superclass._defaultConfig.apply(this, arguments), { |
|
baseCls: "bi-page-table", |
|
el: { |
|
type: "bi.sequence_table" |
|
}, |
|
pager: { |
|
horizontal: { |
|
pages: false, //总页数 |
|
curr: 1, //初始化当前页, pages为数字时可用 |
|
|
|
hasPrev: BI.emptyFn, |
|
hasNext: BI.emptyFn, |
|
firstPage: 1, |
|
lastPage: BI.emptyFn |
|
}, |
|
vertical: { |
|
pages: false, //总页数 |
|
curr: 1, //初始化当前页, pages为数字时可用 |
|
|
|
hasPrev: BI.emptyFn, |
|
hasNext: BI.emptyFn, |
|
firstPage: 1, |
|
lastPage: BI.emptyFn |
|
} |
|
}, |
|
|
|
itemsCreator: BI.emptyFn, |
|
|
|
isNeedFreeze: false,//是否需要冻结单元格 |
|
freezeCols: [], //冻结的列号,从0开始,isNeedFreeze为true时生效 |
|
|
|
isNeedMerge: false,//是否需要合并单元格 |
|
mergeCols: [], //合并的单元格列号 |
|
mergeRule: BI.emptyFn, |
|
|
|
columnSize: [], |
|
minColumnSize: [], |
|
maxColumnSize: [], |
|
headerRowSize: 25, |
|
rowSize: 25, |
|
|
|
regionColumnSize: [], |
|
|
|
headerCellStyleGetter: BI.emptyFn, |
|
summaryCellStyleGetter: BI.emptyFn, |
|
sequenceCellStyleGetter: BI.emptyFn, |
|
|
|
header: [], |
|
items: [], //二维数组 |
|
|
|
//交叉表头 |
|
crossHeader: [], |
|
crossItems: [] |
|
}); |
|
}, |
|
|
|
_init: function () { |
|
BI.PageTable.superclass._init.apply(this, arguments); |
|
var self = this, o = this.options; |
|
this.hCurr = 1; |
|
this.vCurr = 1; |
|
|
|
this.table = BI.createWidget(o.el, { |
|
type: "bi.sequence_table", |
|
width: o.width, |
|
height: o.height && o.height - 30, |
|
|
|
isNeedResize: true, |
|
isResizeAdapt: false, |
|
|
|
isNeedFreeze: o.isNeedFreeze, |
|
freezeCols: o.freezeCols, |
|
|
|
isNeedMerge: o.isNeedMerge, |
|
mergeCols: o.mergeCols, |
|
mergeRule: o.mergeRule, |
|
|
|
columnSize: o.columnSize, |
|
minColumnSize: o.minColumnSize, |
|
maxColumnSize: o.maxColumnSize, |
|
headerRowSize: o.headerRowSize, |
|
rowSize: o.rowSize, |
|
|
|
regionColumnSize: o.regionColumnSize, |
|
|
|
headerCellStyleGetter: o.headerCellStyleGetter, |
|
summaryCellStyleGetter: o.summaryCellStyleGetter, |
|
sequenceCellStyleGetter: o.sequenceCellStyleGetter, |
|
|
|
header: o.header, |
|
items: o.items, |
|
//交叉表头 |
|
crossHeader: o.crossHeader, |
|
crossItems: o.crossItems |
|
}); |
|
|
|
this.table.on(BI.Table.EVENT_TABLE_SCROLL, function () { |
|
self.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); |
|
}); |
|
this.table.on(BI.Table.EVENT_TABLE_AFTER_REGION_RESIZE, function () { |
|
o.regionColumnSize = this.getRegionColumnSize(); |
|
o.columnSize = this.getColumnSize(); |
|
self.fireEvent(BI.Table.EVENT_TABLE_AFTER_REGION_RESIZE, arguments); |
|
}); |
|
this.table.on(BI.Table.EVENT_TABLE_AFTER_COLUMN_RESIZE, function () { |
|
o.regionColumnSize = this.getRegionColumnSize(); |
|
o.columnSize = this.getColumnSize(); |
|
self.fireEvent(BI.Table.EVENT_TABLE_AFTER_COLUMN_RESIZE, arguments); |
|
}); |
|
|
|
this.pager = BI.createWidget(o.pager, { |
|
type: "bi.direction_pager", |
|
height: 30 |
|
}); |
|
this.pager.on(BI.Pager.EVENT_CHANGE, function () { |
|
var vpage = this.getVPage && this.getVPage(); |
|
if (BI.isNull(vpage)) { |
|
vpage = this.getCurrentPage(); |
|
} |
|
var hpage = this.getHPage && this.getHPage(); |
|
o.itemsCreator({ |
|
vpage: vpage, |
|
hpage: hpage |
|
}, function (items, header, crossItems, crossHeader) { |
|
self.table.setVPage ? self.table.setVPage(vpage) : self.table.setValue(vpage); |
|
self.table.setHPage && self.table.setHPage(hpage); |
|
self.populate.apply(self, arguments); |
|
}); |
|
}); |
|
|
|
BI.createWidget({ |
|
type: "bi.absolute", |
|
element: this, |
|
items: [{ |
|
el: this.table, |
|
left: 0, |
|
top: 0 |
|
}, { |
|
el: this.pager, |
|
left: 0, |
|
right: 0, |
|
bottom: 0 |
|
}] |
|
}) |
|
}, |
|
|
|
setHPage: function (v) { |
|
this.hCurr = v; |
|
this.pager.setHPage && this.pager.setHPage(v); |
|
this.table.setHPage && this.table.setHPage(v); |
|
}, |
|
|
|
setVPage: function (v) { |
|
this.vCurr = v; |
|
this.pager.setVPage && this.pager.setVPage(v); |
|
this.table.setVPage && this.table.setVPage(v); |
|
}, |
|
|
|
getHPage: function () { |
|
var hpage = this.pager.getHPage && this.pager.getHPage(); |
|
if (BI.isNotNull(hpage)) { |
|
return hpage; |
|
} |
|
hpage = this.pager.getCurrentPage && this.pager.getCurrentPage(); |
|
if (BI.isNotNull(hpage)) { |
|
return hpage; |
|
} |
|
return this.hpage; |
|
}, |
|
|
|
getVPage: function () { |
|
var vpage = this.pager.getVPage && this.pager.getVPage(); |
|
if (BI.isNotNull(vpage)) { |
|
return vpage; |
|
} |
|
vpage = this.pager.getCurrentPage && this.pager.getCurrentPage(); |
|
if (BI.isNotNull(vpage)) { |
|
return vpage; |
|
} |
|
return this.vpage; |
|
}, |
|
|
|
setWidth: function (width) { |
|
BI.PageTable.superclass.setWidth.apply(this, arguments); |
|
this.table.setWidth(width); |
|
}, |
|
|
|
setHeight: function (height) { |
|
BI.PageTable.superclass.setHeight.apply(this, arguments); |
|
var showPager = false; |
|
if (this.pager.alwaysShowPager) { |
|
showPager = true; |
|
} else if (this.pager.hasHNext && this.pager.hasHNext()) { |
|
showPager = true; |
|
} else if (this.pager.hasHPrev && this.pager.hasHPrev()) { |
|
showPager = true; |
|
} else if (this.pager.hasVNext && this.pager.hasVNext()) { |
|
showPager = true; |
|
} else if (this.pager.hasVPrev && this.pager.hasVPrev()) { |
|
showPager = true; |
|
} else if (this.pager.hasNext && this.pager.hasNext()) { |
|
showPager = true; |
|
} else if (this.pager.hasPrev && this.pager.hasPrev()) { |
|
showPager = true; |
|
} |
|
this.table.setHeight(height - (showPager ? 30 : 0)); |
|
}, |
|
|
|
setColumnSize: function (columnSize) { |
|
this.options.columnSize = columnSize; |
|
this.table.setColumnSize(columnSize); |
|
}, |
|
|
|
getColumnSize: function () { |
|
return this.table.getColumnSize(); |
|
}, |
|
|
|
setRegionColumnSize: function (columnSize) { |
|
this.options.columnSize = columnSize; |
|
this.table.setRegionColumnSize(columnSize); |
|
}, |
|
|
|
getRegionColumnSize: function () { |
|
return this.table.getRegionColumnSize(); |
|
}, |
|
|
|
getVerticalScroll: function () { |
|
return this.table.getVerticalScroll(); |
|
}, |
|
|
|
setLeftHorizontalScroll: function (scrollLeft) { |
|
this.table.setLeftHorizontalScroll(scrollLeft); |
|
}, |
|
|
|
setRightHorizontalScroll: function (scrollLeft) { |
|
this.table.setRightHorizontalScroll(scrollLeft); |
|
}, |
|
|
|
setVerticalScroll: function (scrollTop) { |
|
this.table.setVerticalScroll(scrollTop); |
|
}, |
|
|
|
restore: function () { |
|
this.table.restore(); |
|
}, |
|
|
|
attr: function () { |
|
BI.PageTable.superclass.attr.apply(this, arguments); |
|
this.table.attr.apply(this.table, arguments); |
|
}, |
|
|
|
populate: function () { |
|
this.pager.populate(); |
|
this.table.populate.apply(this.table, arguments); |
|
}, |
|
|
|
destroy: function () { |
|
this.table.destroy(); |
|
this.pager && this.pager.destroy(); |
|
BI.PageTable.superclass.destroy.apply(this, arguments); |
|
} |
|
}); |
|
BI.shortcut('bi.page_table', BI.PageTable); |