Skip to main content

Model Filter

The model filter is an interactive component used for filtering operations on specified model data, implementing visual configuration capabilities for data query conditions based on React and TypeScript. It handles query condition construction, filter state management, and query event triggering, supporting three filtering modes: simple mode, complex mode, and free mode, providing list and tag display styles.

The model filter element has a hierarchical structure of Meta (components.Meta) → Type (components.Filter) → Instance. Developers can quickly create model filter instance elements through JitAI's visual development tools.

Of course, developers can also create their own Type elements or modify the official components.FilterType element provided by JitAI in their own App to implement their own encapsulation.

Quick Start

Basic Configuration Example

Basic Usage Example
{
"name": "Filter1",
"title": "User Filter",
"type": "components.Filter",
"config": {
"requireElements": [
{
"name": "models.UserModel",
"type": "models.Meta",
"title": "User Model",
"filter": "",
"orderBy": []
}
],
"mode": "simple",
"firstTimeQuery": true,
"layoutPercent": 1,
"styleMode": "list",
"typeMode": "horizontal",
"config": {
"gender": {
"layout": {
"w": 60, "h": 1, "x": 0, "y": 0,
"i": "gender", "minW": 12, "minH": 1
},
"config": {
"fieldId": "gender",
"showTitle": true,
"multiple": false,
"isAll": false,
"isShowAlias": false,
"group": [
{
"id": "filter-group-1",
"type": "normal",
"name": "Male",
"operator": "isEqual",
"filter": [
{
"uid": "item-1",
"fieldId": "gender",
"operator": "isEqual",
"value": "male",
"valueType": "constant",
"type": "ITEM"
}
]
}
],
"isCustom": true,
"rowNum": 1,
"isShowMore": false
}
}
}
}
}

Configuration Properties

Property NameTypeRequiredDefault ValueDescription
requireElementsrequireElement[]Yes-Associated model element configuration
modeFilterModeEnumNo'simple'Filter mode: simple/complex/free
firstTimeQuerybooleanNotrueWhether to query on first load
layoutPercentnumberNo1Layout percentage
styleModeSimpleFilterStyleEnumNo'list'Simple mode style: list/tag
typeModeSimpleFilterTypeEnumNo'horizontal'Simple mode type: horizontal/vertical
configRecord<string, IFilterSimpleConfigNode>No{}Field filter configuration
isShowAllFieldbooleanNofalseWhether to show all fields

requireElement Configuration

Property NameTypeRequiredDescription
namestringYesModel element fullName
typestringYesFixed value 'models.Meta'
titlestringYesModel display name
filterstringNoPreset filter condition
orderBystring[]NoSorting rules

Field Filter Configuration (IFilterSimpleConfigNodeConfig)

Property NameTypeRequiredDefault ValueDescription
fieldIdstringYes-Field ID
showTitlebooleanNotrueWhether to show field title
multiplebooleanNofalseWhether to support multiple selection
isAllbooleanNofalseWhether to include all options
isShowAliasbooleanNofalseWhether to show field alias
aliasstringNo-Field alias
groupIFilterSimpleConfigGroupItem[]No[]Filter group configuration
defaultSelectedGroupstring[]No[]Default selected groups
hasDefaultSelectbooleanNofalseWhether to have default selection
isCustombooleanNotrueWhether to support custom filtering
customFilterOperateTypestringNo-Custom filter operation type
customFilterInfoIFilterCompItem[]No[]Custom filter information
placeholderstringNo-Placeholder text
rowNumnumberNo1Number of display rows
isShowMorebooleanNofalseWhether to show more options
isFuzzyQuerybooleanNofalseWhether to support fuzzy query

Variables

filter

Filter condition variable, storing all filter conditions of the current component.

PropertyTypeDescription
NamefilterVariable name
TypeQFilterQuery filter condition type
GenericAssociated modelPoints to model specified in requireElements
Read-onlytrueVariable is read-only, maintained internally by component

Usage Example:

Get Filter Conditions
// Get current filter conditions
const currentFilter = this.filter.value;

// Reference filter conditions in other components
{
"dataSource": {
"filter": "{{Filter1.filter}}"
}
}

Methods

reset

Reset all filter conditions of the filter to initial state.

Reset Filter
await this.reset();

runCode

Execute JavaScript code string, code runs in page context.

Parameters:

Parameter NameTypeRequiredDescription
codestringYesJavaScript code to execute

Return Value: any - Code execution result

Execute Dynamic Code
// Get filter conditions
const filterValue = this.runCode('this.filter.value');

// Execute complex logic
const result = this.runCode(`
const condition = this.filter.value;
return condition ? 'Has filter conditions' : 'No filter conditions';
`);

setConfig

Update component configuration.

Parameters:

Parameter NameTypeRequiredDescription
nextPartial<T>YesNew configuration object
cleanbooleanNoWhether to completely replace configuration
Dynamically Modify Configuration
this.setConfig({
styleMode: "tag",
typeMode: "vertical"
});

publishEvent

Publish component events.

Parameters:

Parameter NameTypeRequiredDescription
namestringYesEvent name
exRecord<string, any>NoEvent additional data
Publish Custom Event
await this.publishEvent('customFilter', { 
filterType: 'advanced',
data: filterData
});

subscribeEvent

Subscribe to component events.

Parameters:

Parameter NameTypeRequiredDescription
namestringYesEvent name
evtCbFunctionYesEvent callback function
unSubscribeExistbooleanNoWhether to cancel existing subscriptions

Return Value: string - Event handler ID

Subscribe to Filter Event
const handlerId = this.subscribeEvent('afterFilter', async (data) => {
console.log('Filter conditions:', data.filter.value);
});

unSubscribeEvent

Cancel event subscription.

Parameters:

Parameter NameTypeRequiredDescription
idstringYesEvent handler ID

destroy

Destroy component instance, clean up all resources and event subscriptions.

getPermConfig

Get component permission configuration.

Return Value: Record<string, any> | undefined - Permission configuration object

Events

afterFilter

After query event, triggered when filter conditions change and query is completed.

PropertyTypeDescription
Event NameafterFilterFixed event name
Data ParameterfilterCurrent filter conditions
Trigger TimingAfter filter conditions change and query is completed
Event Handling Example
// Subscribe to after filter event
this.subscribeEvent('afterFilter', async (data) => {
console.log('Filter conditions:', data.filter.value);
// Update other component data
await this.Table1.refresh();
});

Properties

name

Component instance name.

  • Type: string

title

Component display title.

  • Type: string

type

Component type identifier.

  • Type: string

showTitle

Whether to show title.

  • Type: boolean

config

Component configuration object.

  • Type: T

app

Application instance reference.

  • Type: App

page

Page instance reference.

  • Type: BasePage

Advanced Features

Multi-mode Support

Complex Mode Configuration
{
"mode": "complex",
"layoutPercent": 1,
"config": {
"fieldId": {
"layout": { /* Layout configuration */ },
"config": {
"fieldId": "userName",
"isShowAlias": true,
"alias": "User Name"
}
}
}
}

Custom Filter Conditions

Custom Filter Configuration
{
"customFilterInfo": [
{
"uid": "custom-1",
"fieldId": "age",
"operator": "gt",
"value": 18,
"valueType": "constant",
"type": "ITEM"
}
]
}

Dynamic Field Generation

When isShowAllField: true is set, the component automatically generates filter configuration based on the associated model's field definitions, excluding field types that don't support filtering (images, rich text, location, attachments, sub-tables).

JitAI AssistantBeta
Powered by JitAI