筛选框可以用,但是排序功能点的时候没反应, 代码如下 请版主解答 看了一下午也没弄出来
initSpread=()=>{
let spread = this.spread;
if(!_.isEmpty(this.state.spreadData)) {
let data = _.cloneDeep(this.state.spreadData.content);
let direction = GcSpread.Sheets.RangeGroupDirection.Backward;
this.initGroup(spread, data, direction,this.state.spreadData.frozenCol,this.state.spreadData.frozenRow);
spread.showVerticalScrollbar(true);
spread.tabNavigationVisible(false);
spread.tabStripVisible(false);
spread.showHorizontalScrollbar(true);
spread.grayAreaBackColor('white');
spread.showScrollTip(GcSpread.Sheets.ShowScrollTip.Horizontal);
this.spreadProtected(spread);
this.setState({
dataReady:true
})
}else{
//spread.fromJSON(this.state.spreadData || '');
spread.showVerticalScrollbar(true);
spread.showHorizontalScrollbar(true);
spread.grayAreaBackColor('white');
spread.showScrollTip(GcSpread.Sheets.ShowScrollTip.Horizontal);
this.spreadProtected(spread);
}
}
spreadProtected=(spread)=> {
let activeSheet = spread.getActiveSheet();
activeSheet.setIsProtected(true);
activeSheet.protectionOption({
allowResizeRows: true,
allowResizeColumns: true,
allowFilter:true,
allowSort:true,
allowEditObjects:false
});
}
initGroup=(spread,data,direction,frozenCol,frozenRow)=> {
let sheets = data.sheets;
let self = this;
let sheetItem = _.values(sheets)[0;
let rows = sheetItem.rows; //取sheets对象里面的第一个value值
let rowNum = sheetItem.rowCount;
let firstHide = "",lastHide="",groupShow={};
//sheet.showRowRangeGroup(true);
rows.map(function (row,index) {
if(row.visible){//如果是可见的。判断是否有一个不可以见的作为开头,若没有则继续遍历,如果有则需要一个结尾
if(firstHide){
lastHide = index;
}
}else{//如果不可见,判断是否有不可见的作为开头,没有就将此作为开头
if(!firstHide){
firstHide = index;
}
if(index == rows.length-1){
lastHide = index+1;
}
row.visible=true;
row.size=21;
}
if(firstHide&&lastHide){
//sheet.rowRangeGroup.group(firstHide+1, lastHide-firstHide);
groupShow[firstHide] = lastHide-firstHide;
//sheet.rowRangeGroup.group(3, 5);
//console.log("隐藏",firstHide+1, lastHide)
firstHide = "";
lastHide = "";
}
});
spread.fromJSON(data);
let sheet = spread.getActiveSheet();
sheet.setRowHeaderVisible(false);
sheet.setColumnHeaderVisible(false);
sheet.rowRangeGroup.setDirection(direction);
sheet.isPaintSuspended(true);
//设置自动换行
for(let i=0 ; i<rowNum ; i++){
sheet.getRow(i).wordWrap(true);
sheet.autoFitRow(i);
}
for(let i in groupShow){
//console.log(i,groupShow)
sheet.rowRangeGroup.group(parseInt(i), parseInt(groupShow[i));
}
if(frozenCol != undefined){
sheet.setFrozenColumnCount(frozenCol);
}
if(frozenRow != undefined){
sheet.setFrozenRowCount(frozenRow);
}
this.setFilter(sheet,_.values(sheets)[0,frozenRow);
sheet.isPaintSuspended(false);
sheet.bind("CellClick", function(a,b,c,d,args) { // sheet event
if(b.col<2){
// message.warning('请选择有效单元格!');
return;
}
if(b.row){
let po = {
date:self.state.date,
col:b.col,
row:b.row,
dataTable:sheetItem.data.dataTable
}
self.setState({
showOpt:true,
detailPo:po
})
}
});
}
setFilter=(activeSheet,data,frozenRow)=>{
let rowCount = data.rowCount,
colCount = data.columnCount;
var cfs = activeSheet.getConditionalFormats();
console.log('activeSheet data frozenRow',activeSheet,data,frozenRow,cfs);
let cellrange =new GcSpread.Sheets.Range(frozenRow||1, 1, rowCount-(frozenRow||1), colCount-1);
let hideRowFilter =new GcSpread.Sheets.HideRowFilter(cellrange);
let rowFilter = activeSheet.rowFilter(hideRowFilter);
}
|
|