2.2.4.5.48 Column::SetFilter
Version
Minimum Origin Version Required: Origin 2016 SR0
Description
Add data filter to column.
Syntax
BOOL SetFilter( int nType, LPVOID data, BOOL bUndo = FALSE )
Parameters
- nType
- [input]the column filter type enum
- {
- COLUMN_FILTER_TYPE_NONE = -1,
- COLUMN_FILTER_TYPE_CHECK_LIST = 0,
- COLUMN_FILTER_TYPE_CUSTOM,
- COLUMN_FILTER_TYPE_COMMAND,
- COLUMN_FILTER_TYPE_DATASET_FUNC,
- };
- data
- [input]struct with filter settings. Each filter type has its own struct. See examples for detail.
- bUndo
- [input] whether the action should be undoable.
Return
TRUE if success
Examples
EX1
void Column_SetFilter_ex1()
{
Worksheet wks;
if( wks.Create("origin") )
{
vector<string> vsData = {"one", "two", "three", "four", "five"};
Dataset ds(wks, 0);
ds.PutStringArray(vsData);
}
vector<string> vsFilter = {"three", "five"};
string strFilter;
strFilter.SetTokens(vsFilter, COLUMN_FILTER_CHECK_LIST_SEP);
CheckListColumnFilterData mydata;
mydata.lpcszValues = strFilter;
Column col(wks, 0);
col.SetFilter((int)COLUMN_FILTER_TYPE_CHECK_LIST, (LPVOID)&mydata);
wks.RunFilter(QUERY_FILTER_ACT_HIDE_NOT_MATCHED, -1, -1, true);
}
EX2
void Column_SetFilter_ex2()
{
Worksheet wks;
if( wks.Create("origin") )
{
Dataset ds(wks, 0);
ds.Data(1, 10);
}
CustomColumnFilterData mydata;
mydata.cond[0].nObjType = CUSTOM_COLUMN_FILTER_OBJECT_NUMERIC;
mydata.cond[0].nFormulaType = CUSTOM_COLUMN_FILTER_FORMULA_NUMERIC_LARGER;
mydata.cond[0].lpcszValue = "2";
mydata.cond[0].dwOption = 0;
mydata.cond[1].nObjType = CUSTOM_COLUMN_FILTER_OBJECT_NUMERIC;
mydata.cond[1].nFormulaType = CUSTOM_COLUMN_FILTER_FORMULA_NUMERIC_LESS;
mydata.cond[1].lpcszValue = "6";
mydata.cond[1].dwOption = 0;
mydata.nLogic = CUSTOM_COLUMN_FILTER_LOGIC_ALL_AND;
Column col(wks, 0);
col.SetFilter((int)COLUMN_FILTER_TYPE_CUSTOM, (LPVOID)&mydata);
wks.RunFilter(QUERY_FILTER_ACT_HIDE_NOT_MATCHED, -1, -1, true);
}
EX3
void Column_SetFilter_ex3()
{
Worksheet wks;
if( wks.Create("origin") )
{
Dataset ds(wks, 0);
ds.Data(1, 10);
}
CommandColumnFilterData mydata;
mydata.lpcszCommand = "col <= 2 or col > 6";
Column col(wks, 0);
col.SetFilter((int)COLUMN_FILTER_TYPE_COMMAND, (LPVOID)&mydata);
col.SetFilterThisCol("col");
wks.RunFilter(QUERY_FILTER_ACT_HIDE_NOT_MATCHED, -1, -1, true);
}
EX4
void Column_SetFilter_ex4()
{
Worksheet wks;
if( wks.Create("origin") )
{
Dataset ds(wks, 0);
ds.Uniform(30);
}
DatasetFuncColumnFilterData mydata;
mydata.lpcszFunc = "top";
mydata.lpcszArgs = "10,1";//10,0: top 10; 10,1: top 10%
Column col(wks, 0);
col.SetFilter((int)COLUMN_FILTER_TYPE_DATASET_FUNC, (LPVOID)&mydata);
wks.RunFilter(QUERY_FILTER_ACT_SELECT_MATCHED, -1, -1, true);
}
Remark
See Also
Worksheet::RunFilter, Column::GetFilter, Column::ResetFilter
Header to Included
origin.h
|