spreadJs-demo
罐子类型
月度目标差额
历史完成月度
上月是否完成规划
esheetSearch.js
$(function(){
//自定已筛选
function CustomFilter(){
GC.Spread.Sheets.ConditionalFormatting.Condition.apply(this, arguments);
};
CustomFilter.prototype = new GC.Spread.Sheets.ConditionalFormatting.Condition();
CustomFilter.prototype.evaluate = function (evaluator, row, col) {
var value = evaluator.getValue(row, col);
if (value !== '' && isNumber(value.trim())) {
return true;
} else {
return false;
}
};
document.getElementById('searchBtn').onclick = function() {
var sheet = spread.getActiveSheet();
var searchCondition = getSearchCondition();
var searchResult = null;
var sels = sheet.getSelections();
if (sels.length > 1) {
searchCondition.searchFlags |= spreadNS.Search.SearchFlags.blockRange;
} else if (sels.length == 1) {
var spanInfo = getSpanInfo(sheet, sels[0].row, sels[0].col);
if (sels[0].rowCount != spanInfo.rowSpan && sels[0].colCount != spanInfo.colSpan) {
searchCondition.searchFlags |= spreadNS.Search.SearchFlags.blockRange;
}
}
searchResult = getResultSearchinSheetEnd(searchCondition);
if (searchResult == null || searchResult.searchFoundFlag == spreadNS.Search.SearchFoundFlags.none) {
searchResult = getResultSearchinSheetBefore(searchCondition);
}
if (searchResult != null && searchResult.searchFoundFlag != spreadNS.Search.SearchFoundFlags.none) {
spread.setActiveSheetIndex(searchResult.foundSheetIndex);
var sheet = spread.getActiveSheet();
sheet.setActiveCell(searchResult.foundRowIndex, searchResult.foundColumnIndex);
if ((searchCondition.searchFlags & spreadNS.Search.SearchFlags.blockRange) == 0) {
sheet.setActiveCell(searchResult.foundRowIndex, searchResult.foundColumnIndex, 1, 1);
}
//scrolling
if (searchResult.foundRowIndex < sheet.getViewportTopRow(1) ||
searchResult.foundRowIndex > sheet.getViewportBottomRow(1) ||
searchResult.foundColumnIndex < sheet.getViewportLeftColumn(1) ||
searchResult.foundColumnIndex > sheet.getViewportRightColumn(1)
) {
sheet.showCell(searchResult.foundRowIndex,
searchResult.foundColumnIndex,
spreadNS.VerticalPosition.center,
spreadNS.HorizontalPosition.center);
} else {
sheet.repaint();
}
} else {
//Not Found
alert('Not Found');
}
};
//罐子类型筛选
$("#viewType").change(function(){
var sheet = spread.getActiveSheet(),
filter = sheet.rowFilter(),
value = $("#viewType").val();
col = columnNums-1;
if (filter) {
if(''==value){
value="*";
}
filter.removeFilterItems(col);
var condition = new spreadNS.ConditionalFormatting.Condition(spreadNS.ConditionalFormatting.ConditionType.textCondition, {
compareType: spreadNS.ConditionalFormatting.TextCompareType.contains,
expected: value
});
filter.addFilterItem(col, condition);
filter.filter();
sheet.invalidateLayout();
sheet.repaint();
}
});
//月度差额
$("#monthCE").change(function(){
var sheet = spread.getActiveSheet(),
filter = sheet.rowFilter(),
value = $("#monthCE").val();
col = columnNums-4;
if (filter) {
if(''==value){
value="*";
}else if("Y"==value){
value='已完成';
}
filter.removeFilterItems(col);
var condition = new spreadNS.ConditionalFormatting.Condition(spreadNS.ConditionalFormatting.ConditionType.textCondition, {
compareType: spreadNS.ConditionalFormatting.TextCompareType.contains,
expected: value
});
if('N'==value){
var condition1 = new spreadNS.ConditionalFormatting.Condition(spreadNS.ConditionalFormatting.ConditionType.textCondition, {
compareType: spreadNS.ConditionalFormatting.TextCompareType.doesNotContain,
expected: '已完成'
});
var condition2 = new spreadNS.ConditionalFormatting.Condition(spreadNS.ConditionalFormatting.ConditionType.textCondition, {
compareType: spreadNS.ConditionalFormatting.TextCompareType.notEqualsTo,
expected: ''
});
var conditions=getComplexCondition(condition1,condition2);
filter.addFilterItem(col, conditions);
}else{
filter.addFilterItem(col, condition);
}
filter.filter();
sheet.invalidateLayout();
sheet.repaint();
}
});
//历史完成月度
$("#hisCompletedMonth").change(function(){
var sheet = spread.getActiveSheet(),
filter = sheet.rowFilter(),
value = $("#hisCompletedMonth").val();
col = columnNums-3;
if (filter) {
if(''==value){
value="*";
}else if('1个月'==value){
value='/1个月';
}
filter.removeFilterItems(col);
var condition = new spreadNS.ConditionalFormatting.Condition(spreadNS.ConditionalFormatting.ConditionType.textCondition, {
compareType: spreadNS.ConditionalFormatting.TextCompareType.contains,
expected: value
});
if('x个月'==value){
var condition1 = new spreadNS.ConditionalFormatting.Condition(spreadNS.ConditionalFormatting.ConditionType.textCondition, {
compareType: spreadNS.ConditionalFormatting.TextCompareType.doesNotContain,
expected: '/1个月'
});
var condition2 = new spreadNS.ConditionalFormatting.Condition(spreadNS.ConditionalFormatting.ConditionType.textCondition, {
compareType: spreadNS.ConditionalFormatting.TextCompareType.notEqualsTo,
expected: ''//null也可以
});
/* var condition2 = new GC.Spread.Sheets.ConditionalFormatting.Condition(GC.Spread.Sheets.ConditionalFormatting.ConditionType.formulaCondition,{
compareType: GC.Spread.Sheets.ConditionalFormatting.CustomValueType.nonEmpty
});*/
var conditions=getComplexCondition(condition1,condition2);
filter.addFilterItem(col, conditions);
}else{
filter.addFilterItem(col, condition);
}
filter.filter();
sheet.invalidateLayout();
sheet.repaint();
}
});
//上月是否完成规划
$("#hasCompletedMonthPlan").change(function(){
var sheet = spread.getActiveSheet(),
filter = sheet.rowFilter(),
value = $("#hasCompletedMonthPlan").val();
col = columnNums-2;
if (filter) {
if(''==value){
value="*";
}
filter.removeFilterItems(col);
var condition = new spreadNS.ConditionalFormatting.Condition(spreadNS.ConditionalFormatting.ConditionType.textCondition, {
compareType: spreadNS.ConditionalFormatting.TextCompareType.contains,
expected: value
});
filter.addFilterItem(col, condition);
filter.filter();
sheet.invalidateLayout();
sheet.repaint();
}
});
});
function getComplexCondition(condition1,condition2){
var conditions = new GC.Spread.Sheets.ConditionalFormatting.Condition(GC.Spread.Sheets.ConditionalFormatting.ConditionType.relationCondition, {
compareType: spreadNS.ConditionalFormatting.LogicalOperators.and,
item1: condition1,
item2: condition2
});
return conditions;
}
function getSpanInfo(sheet, row, col) {
var span = sheet.getSpans(new spreadNS.Range(row, col, 1, 1));
if (span.length > 0) {
return {
rowSpan : span[0].rowCount,
colSpan : span[0].colCount
};
} else {
return {
rowSpan : 1,
colSpan : 1
};
}
}
function getResultSearchinSheetEnd(searchCondition) {
var sheet = spread.getActiveSheet();
searchCondition.startSheetIndex = spread.getActiveSheetIndex();
searchCondition.endSheetIndex = spread.getActiveSheetIndex();
if (searchCondition.searchOrder == spreadNS.Search.SearchOrder.zOrder) {
searchCondition.findBeginRow = sheet.getActiveRowIndex();
searchCondition.findBeginColumn = sheet.getActiveColumnIndex() + 1;
} else if (searchCondition.searchOrder == spreadNS.Search.SearchOrder.nOrder) {
searchCondition.findBeginRow = sheet.getActiveRowIndex() + 1;
searchCondition.findBeginColumn = sheet.getActiveColumnIndex();
}
if ((searchCondition.searchFlags & spreadNS.Search.SearchFlags.blockRange) > 0) {
var sel = sheet.getSelections()[0];
searchCondition.rowStart = sel.row;
searchCondition.columnStart = sel.col;
searchCondition.rowEnd = sel.row + sel.rowCount - 1;
searchCondition.columnEnd = sel.col + sel.colCount - 1;
}
var searchResult = spread.search(searchCondition);
return searchResult;
}
function getResultSearchinSheetBefore(searchCondition) {
var sheet = spread.getActiveSheet();
searchCondition.startSheetIndex = spread.getActiveSheetIndex();
searchCondition.endSheetIndex = spread.getActiveSheetIndex();
if ((searchCondition.searchFlags & spreadNS.Search.SearchFlags.blockRange) > 0) {
var sel = sheet.getSelections()[0];
searchCondition.rowStart = sel.row;
searchCondition.columnStart = sel.col;
searchCondition.findBeginRow = sel.row;
searchCondition.findBeginColumn = sel.col;
searchCondition.rowEnd = sel.row + sel.rowCount - 1;
searchCondition.columnEnd = sel.col + sel.colCount - 1;
} else {
searchCondition.rowStart = -1;
searchCondition.columnStart = -1;
searchCondition.findBeginRow = -1;
searchCondition.findBeginColumn = -1;
searchCondition.rowEnd = sheet.getActiveRowIndex();
searchCondition.columnEnd = sheet.getActiveColumnIndex();
}
var searchResult = spread.search(searchCondition);
return searchResult;
}
function getResultSearchinWorkbookEnd(searchCondition) {
searchCondition.rowStart = -1;
searchCondition.columnStart = -1;
searchCondition.findBeginRow = -1;
searchCondition.findBeginColumn = -1;
searchCondition.rowEnd = -1;
searchCondition.columnEnd = -1;
searchCondition.startSheetIndex = spread.getActiveSheetIndex() + 1;
searchCondition.endSheetIndex = -1;
var searchResult = spread.search(searchCondition);
return searchResult;
}
function getResultSearchinWorkbookBefore(searchCondition) {
searchCondition.rowStart = -1;
searchCondition.columnStart = -1;
searchCondition.findBeginRow = -1;
searchCondition.findBeginColumn = -1;
searchCondition.rowEnd = -1;
searchCondition.columnEnd = -1;
searchCondition.startSheetIndex = -1
searchCondition.endSheetIndex = spread.getActiveSheetIndex() - 1;
var searchResult = spread.search(searchCondition);
return searchResult;
}
function getSearchCondition(searchString) {
var searchCondition = new spreadNS.Search.SearchCondition();
var searchString=$("#inputValue").val();
searchCondition.searchString = searchString;
searchCondition.startSheetIndex = spread.getActiveSheetIndex();
searchCondition.endSheetIndex = spread.getActiveSheetIndex();
searchCondition.searchOrder = spreadNS.Search.SearchOrder.zOrder;
searchCondition.searchTarget = spreadNS.Search.SearchFoundFlags.cellText;
searchCondition.searchFlags |= spreadNS.Search.SearchFlags.ignoreCase;
return searchCondition;
}