structured-filter is a generic Web UI for building structured search or filter queries.
With it you can build structured search conditions like Firstname starts with 'A' and Birthday after 1/1/1980 and State in (CA, NY, FL)... It is a full jQuery UI widget, supporting various configurations and themes.
Check the demo for live examples.
# To get the latest stable version, use git from the command line.git clone
or install the npm package:
# To get the latest stable version, use npm from the command line.npm install structured-filter
or install with Bower:
# To get the latest stable version, use Bower from the command line.bower install structured-filter# To get the most recent, latest committed-to-master version use:bower install structured-filter#master
Notes: If you use a version of jQuery-UI smaller than 1.12.1, you must use Structured-Filter version 1.1.0.
The widget requires a jQuery UI theme to be present, as well as its own included base CSS file (structured-filter.css). Here we use the "ui-lightness" theme as an example:
Now, let's attach it to an existing
This will change the
<div> into the widget.
The widget is configured with a list of fields to use in the search conditions.
Each field must have an ID, a type, and a label.
Fields of type "list" must also have a "list" property for the values (array of objects with id and label).
fields =id:"lastname" type:"text" label:"Lastname"id:"firstname" type:"text" label:"Firstname"id:"active" type:"boolean" label:"Is active"id:"age" type:"number" label:"Age"id:"bday" type:"date" label:"Birthday"id:"category" type:"list" label:"Category"list:id:"1" label:"Family"id:"2" label:"Friends"...;
Note: To change the behavior of a "list" field, use the type "list-options" and "list-dropdown" instead of "list".
Queries are expressed as a set of conditions.
Each condition is defined by:
For each field the possible operators are determined by it's type.
structured-filter provides several options to customize its behaviour:
The labels of buttons used to manipulate filters. This options applies to the 3 buttons, "New filter", "Add filter"/"Update filter" and "Cancel" which use icons if the option is set to false.
Defaults to false.
The format for parsed and displayed dates. This attribute is one of the regionalisation attributes. Common formats are: Default - "mm/dd/yy", ISO 8601 - "yy-mm-dd", Short - "d M, y", Medium - "d MM, y", Full - "DD, d MM, yy". For a full list of the possible formats see the jQuery formatDate function.
Defaults to "mm/dd/yy".
The list of fields (as an array of objects with id, label and type) to participate in the query definition. Possible types are: text, boolean, number, date, time, and list.
Defaults to [ ].
A highlight animation performed on the last added or modified filter.
Defaults to true.
Shows or hides the "Submit" button.
Defaults to false.
Provides hidden fields with the conditions' values to be submitted with the form (as an alternative to an AJAX call).
Defaults to false.
Adds a new filter condition.
Removes all search filters.
Gets the number of filters.
Removes the condition of the specified index.
Gets or sets the filter definition (as an array of filters).
field:label: "Lastname"value: "Lastname"operator:label: "starts with"value: "sw"value:label: "\"jo\""value: "jo"
Gets the filter definition (as a readable text string).
Lastname starts with "jo"
Gets the filter definition (as a URL string).
This event is triggered when the list of search conditions is modified.
This event is triggered when the submit button is clicked.
Copyright (c) 2017 Olivier Giulieri.
structured-filter is released under the MIT license.