Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@kerwin612/ngx-query-builder

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kerwin612/ngx-query-builder

[![npm version](https://badge.fury.io/js/@kerwin612%2Fngx-query-builder.svg)](https://badge.fury.io/js/@kerwin612%2Fngx-query-builder) [![npm downloads a month](https://img.shields.io/npm/dm/@kerwin612%2Fngx-query-builder.svg)](https://img.shields.io/npm/

  • 0.6.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

ngx-query-builder

npm version npm downloads a month npm downloads a week

A modernized Angular 4+ query builder based on jQuery QueryBuilder. Support for heavy customization with Angular components and provides a flexible way to handle custom data types.

Forked from (https://github.com/zebzhao/Angular-QueryBuilder) as the original project has stopped updating and does not support the latest Angular versions, so I will continue to maintain it and support the latest versions of Angular.

Getting Started

Install

  • Angular latest, use 0.6.3+

npm install @kerwin612/ngx-query-builder


  • Angular 9, use 0.6.0
  • Angular 8, use 0.5.1
  • Angular 6-7, use 0.4.2
  • Angular 4-5, use 0.3.2

npm install angular2-query-builder

See https://github.com/zebzhao/Angular-QueryBuilder for more details on the usage of the old version.

Examples

Basic Usage

app.module.ts
import { QueryBuilderModule } from "ngx-query-builder";
import { AppComponent } from "./app.component"

@NgModule(imports: [
  ...,
  QueryBuilderModule,
  IonicModule.forRoot(AppComponent) // (Optional) for IonicFramework 2+
])
export class AppModule { }
app.component.html
...
<ngx-query-builder [(ngModel)]='query' [config]='config'></ngx-query-builder>
...
app.component.ts
import { QueryBuilderConfig } from 'ngx-query-builder';

export class AppComponent {
  query = {
    condition: 'and',
    rules: [
      {field: 'age', operator: '<=', value: 'Bob'},
      {field: 'gender', operator: '>=', value: 'm'}
    ]
  };
  
  config: QueryBuilderConfig = {
    fields: {
      age: {name: 'Age', type: 'number'},
      gender: {
        name: 'Gender',
        type: 'category',
        options: [
          {name: 'Male', value: 'm'},
          {name: 'Female', value: 'f'}
        ]
      }
    }
  }
}

Custom Input Components

app.component.html
<ngx-query-builder [(ngModel)]='query' [config]='config'>
  <ng-container *queryInput="let rule; type: 'date'">
    <custom-datepicker [(ngModel)]="rule.value"></custom-datepicker>
  </ng-container>
</ngx-query-builder>
app.component.ts
query = {
  condition: 'and',
  rules: [
    {field: 'birthday', operator: '=', value: new Date()}
  ]
};

config: QueryBuilderConfig = {
  fields: {
    birthday: {name: 'Birthday', type: 'date', operators: ['=', '<=', '>']
      defaultValue: (() => return new Date())
    },
  }
}

Property Bindings Quick Reference

ngx-query-builder
NameTypeRequiredDefaultDescription
allowRulesetbooleanOptionaltrueDisplays the + Ruleset button if true.
allowCollapsebooleanOptionalfalseEnables collapsible rule sets if true.
classNamesQueryBuilderClassNamesOptionalCSS class names for different child elements in query-builder component.
configQueryBuilderConfigRequiredConfiguration object for the main component.
dataRulesetOptional{ condition: 'and', rules: [] }(Use ngModel or value instead.)
emptyMessagestringOptionalMessage to display for an empty Ruleset if empty rulesets are not allowed.
ngModelRulesetOptional{ condition: 'and', rules: [] }Object that stores the state of the component. Supports 2-way binding.
operatorMap{ [key: string]: string[] }OptionalUsed to map field types to list of operators.
persistValueOnFieldChangebooleanOptionalfalseIf true, when a field changes to another of the same type, and the type is one of: string, number, time, date, or boolean, persist the previous value. This option is ignored if config.calculateFieldChangeValue is provided.
config.calculateFieldChangeValue(currentField: Field, nextField: Field, currentValue: any) => anyOptionalUsed to calculate the new value when a rule's field changes.
valueRulesetOptional{ condition: 'and', rules: [] }Object that stores the state of the component.

Structural Directives

Use these directives to replace different parts of query builder with custom components.

queryArrowIcon

Directive to replace the expand arrow used in collapse/accordion mode of the query builder.

Context NameTypeDescription
$implicitRuleSetCurrent rule set object which contain a list of child rules
getDisabledState() => booleanRetrieves or determines the disabled state of the component
querySwitchGroup

Useful for replacing the switch controls, for example the AND/OR conditions. More custom conditions can be specified by using this directive to override the default component.

Context NameTypeDescription
$implicitRuleSetCurrent rule set object which contain a list of child rules
onChange() => voidCallback to handle changes to the switch group component
getDisabledState() => booleanRetrieves or determines the disabled state of the component
queryButtonGroup

For replacing the default button group for Add, Add Ruleset, Remove Ruleset buttons.

Context NameTypeDescription
$implicitRuleSetCurrent rule set object which contain a list of child rules
parentValueRuleSetFor parent node's data if exists
addRule() => voidFunction to handle adding a new rule
addRuleSet() => voidFunction to handle adding a new rule set
removeRuleSet() => voidFunction to handle removing the current rule set
getDisabledState() => booleanRetrieves or determines the disabled state of the component
queryRulesetAddRuleButton

For replacing the default button for Add Rule.

Context NameTypeDescription
$implicitRuleSetCurrent rule set object which contain a list of child rules
addRule() => voidFunction to handle adding a new rule
getDisabledState() => booleanRetrieves or determines the disabled state of the component
queryRulesetAddRulesetButton

For replacing the default button for Add Ruleset.

Context NameTypeDescription
$implicitRuleSetCurrent rule set object which contain a list of child rules
addRuleSet() => voidFunction to handle adding a new rule set
getDisabledState() => booleanRetrieves or determines the disabled state of the component
queryRulesetRemoveButton

For replacing the default button for Remove Ruleset.

Context NameTypeDescription
$implicitRuleSetCurrent rule set object which contain a list of child rules
removeRuleSet() => voidFunction to handle removing the current rule set
getDisabledState() => booleanRetrieves or determines the disabled state of the component
queryEntity

Used to replace entity selection component.

Context NameTypeDescription
$implicitRuleCurrent rule object which contains the field, value, and operator
entitiesEntity[]List of entities for the component, specified by config
onChange(entityValue: string, rule: Rule) => voidCallback to handle changes to the entity component
getDisabledState() => booleanRetrieves or determines the disabled state of the component
queryField

Used this directive to replace the query field selection component.

Context NameTypeDescription
$implicitRuleCurrent rule object which contains the field, value, and operator
getFields(entityName: string) => voidGet the list of fields corresponding to an entity
fieldsField[]List of fields for the component, specified by config
onChange(fieldValue: string, rule: Rule) => voidCallback to handle changes to the field component
getDisabledState() => booleanRetrieves or determines the disabled state of the component
queryOperator

Used to replace the query operator selection component.

Context NameTypeDescription
$implicitRuleCurrent rule object which contains the field, value, and operator
operatorsstring[]List of operators for the field, returned by getOperators
onChange() => voidCallback to handle changes to the operator component
getDisabledState() => booleanRetrieves or determines the disabled state of the component
queryInput

Used to replace the input component. Specify the type/queryInputType to match specific field types to input template.

Context NameTypeDescription
$implicitRuleCurrent rule object which contains the field, value, and operator
fieldFieldCurrent field object which contains the field's value and name
optionsOption[]List of options for the field, returned by getOptions
onChange() => voidCallback to handle changes to the input component
getDisabledState() => booleanRetrieves or determines the disabled state of the component
queryRuleRemoveButton

Directive to replace the default remove single rule button component.

Context NameTypeDescription
$implicitRuleCurrent rule object which contains the field, value, and operator
removeRule(rule: Rule) => voidFunction to handle removing a rule
getDisabledState() => booleanRetrieves or determines the disabled state of the component
queryEmptyWarning

Can be used to customize the default empty warning message, alternatively can specify the emptyMessage property binding.

Context NameTypeDescription
$implicitRuleSetCurrent rule set object which contain a list of child rules
messagestringValue passed to emptyMessage
getDisabledState() => booleanRetrieves or determines the disabled state of the component

Dependencies

  • Angular 18+

Development

dev

demo preview

demo demo

build

  • pnpm build

publish

cd dist/ngx-query-builder
npm publish --access public

For use in other local projects

cd dist/ngx-query-builder
npm link

cd /path/to/other/project
npm link ngx-query-builder

That's it.

FAQs

Package last updated on 19 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc