datatables.net-searchbuilder 1.2.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/js/dataTables.searchBuilder.js +418 -179
- package/js/dataTables.searchBuilder.min.js +123 -113
- package/package.json +4 -3
- package/types/criteria.d.ts +255 -0
- package/types/group.d.ts +189 -0
- package/types/index.d.ts +4 -0
- package/types/searchBuilder.d.ts +153 -0
- package/types/types.d.ts +40 -0
package/package.json
CHANGED
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
"description": "SearchBuilder for DataTables",
|
|
4
4
|
"main": "js/dataTables.searchBuilder.js",
|
|
5
5
|
"types": "./types/types.d.ts",
|
|
6
|
-
"version": "1.
|
|
6
|
+
"version": "1.3.1",
|
|
7
7
|
"files": [
|
|
8
|
-
"js/**/*.js"
|
|
8
|
+
"js/**/*.js",
|
|
9
|
+
"types/**/*.d.ts"
|
|
9
10
|
],
|
|
10
11
|
"keywords": [
|
|
11
12
|
"SearchBuilder",
|
|
@@ -18,7 +19,7 @@
|
|
|
18
19
|
"sort"
|
|
19
20
|
],
|
|
20
21
|
"dependencies": {
|
|
21
|
-
"datatables.net": ">=1.
|
|
22
|
+
"datatables.net": ">=1.11.3",
|
|
22
23
|
"jquery": ">=1.7"
|
|
23
24
|
},
|
|
24
25
|
"moduleType": [
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
/// <reference types="jquery" />
|
|
2
|
+
/// <reference types="datatables.net" />
|
|
3
|
+
import * as builderType from './searchBuilder';
|
|
4
|
+
export interface IClasses {
|
|
5
|
+
button: string;
|
|
6
|
+
buttonContainer: string;
|
|
7
|
+
condition: string;
|
|
8
|
+
container: string;
|
|
9
|
+
data: string;
|
|
10
|
+
delete: string;
|
|
11
|
+
dropDown: string;
|
|
12
|
+
greyscale: string;
|
|
13
|
+
input: string;
|
|
14
|
+
italic: string;
|
|
15
|
+
joiner: string;
|
|
16
|
+
left: string;
|
|
17
|
+
notItalic: string;
|
|
18
|
+
option: string;
|
|
19
|
+
right: string;
|
|
20
|
+
select: string;
|
|
21
|
+
value: string;
|
|
22
|
+
vertical: string;
|
|
23
|
+
}
|
|
24
|
+
export interface ICondition {
|
|
25
|
+
conditionName: string | ((dt: any, i18n: any) => string);
|
|
26
|
+
init: (that?: Criteria, fn?: (thatAgain: Criteria, el: JQuery<HTMLElement>) => void, preDefined?: string[]) => JQuery<HTMLElement> | Array<JQuery<HTMLElement>> | void;
|
|
27
|
+
inputValue: (el: JQuery<HTMLElement>) => string[] | void;
|
|
28
|
+
isInputValid: (val: Array<JQuery<HTMLElement>>, that: Criteria) => boolean;
|
|
29
|
+
search: (value: string, comparison: string[], that: Criteria) => boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface IOrthogonal {
|
|
32
|
+
display: string;
|
|
33
|
+
search: string;
|
|
34
|
+
}
|
|
35
|
+
export interface IDom {
|
|
36
|
+
buttons: JQuery<HTMLElement>;
|
|
37
|
+
condition: JQuery<HTMLElement>;
|
|
38
|
+
conditionTitle: JQuery<HTMLElement>;
|
|
39
|
+
container: JQuery<HTMLElement>;
|
|
40
|
+
data: JQuery<HTMLElement>;
|
|
41
|
+
dataTitle: JQuery<HTMLElement>;
|
|
42
|
+
defaultValue: JQuery<HTMLElement>;
|
|
43
|
+
delete: JQuery<HTMLElement>;
|
|
44
|
+
left: JQuery<HTMLElement>;
|
|
45
|
+
right: JQuery<HTMLElement>;
|
|
46
|
+
value: Array<JQuery<HTMLElement>>;
|
|
47
|
+
valueTitle: JQuery<HTMLElement>;
|
|
48
|
+
}
|
|
49
|
+
export interface IS {
|
|
50
|
+
condition: string;
|
|
51
|
+
conditions: {
|
|
52
|
+
[keys: string]: ICondition;
|
|
53
|
+
};
|
|
54
|
+
data: string;
|
|
55
|
+
dataIdx: number;
|
|
56
|
+
dataPoints: IDataOpt[];
|
|
57
|
+
dateFormat: string | boolean;
|
|
58
|
+
depth: number;
|
|
59
|
+
dt: any;
|
|
60
|
+
filled: boolean;
|
|
61
|
+
index: number;
|
|
62
|
+
origData: string;
|
|
63
|
+
topGroup: JQuery<HTMLElement>;
|
|
64
|
+
type: string;
|
|
65
|
+
value: string[];
|
|
66
|
+
}
|
|
67
|
+
export interface IDataOpt {
|
|
68
|
+
index: number;
|
|
69
|
+
origData: string;
|
|
70
|
+
text: string;
|
|
71
|
+
}
|
|
72
|
+
export interface IDetails {
|
|
73
|
+
condition?: string;
|
|
74
|
+
criteria?: Criteria;
|
|
75
|
+
data?: string;
|
|
76
|
+
index?: number;
|
|
77
|
+
logic?: string;
|
|
78
|
+
origData?: string;
|
|
79
|
+
type?: string;
|
|
80
|
+
value?: string[];
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Sets the value of jQuery for use in the file
|
|
84
|
+
*
|
|
85
|
+
* @param jq the instance of jQuery to be set
|
|
86
|
+
*/
|
|
87
|
+
export declare function setJQuery(jq: any): void;
|
|
88
|
+
/**
|
|
89
|
+
* The Criteria class is used within SearchBuilder to represent a search criteria
|
|
90
|
+
*/
|
|
91
|
+
export default class Criteria {
|
|
92
|
+
private static version;
|
|
93
|
+
private static classes;
|
|
94
|
+
classes: IClasses;
|
|
95
|
+
dom: IDom;
|
|
96
|
+
c: builderType.IDefaults;
|
|
97
|
+
s: IS;
|
|
98
|
+
constructor(table: any, opts: builderType.IDefaults, topGroup: JQuery<HTMLElement>, index?: number, depth?: number);
|
|
99
|
+
/**
|
|
100
|
+
* Escape html characters within a string
|
|
101
|
+
*
|
|
102
|
+
* @param txt the string to be escaped
|
|
103
|
+
* @returns the escaped string
|
|
104
|
+
*/
|
|
105
|
+
private static _escapeHTML;
|
|
106
|
+
/**
|
|
107
|
+
* Default initialisation function for select conditions
|
|
108
|
+
*/
|
|
109
|
+
private static initSelect;
|
|
110
|
+
/**
|
|
111
|
+
* Default initialisation function for select array conditions
|
|
112
|
+
*
|
|
113
|
+
* This exists because there needs to be different select functionality for contains/without and equals/not
|
|
114
|
+
*/
|
|
115
|
+
private static initSelectArray;
|
|
116
|
+
/**
|
|
117
|
+
* Default initialisation function for input conditions
|
|
118
|
+
*/
|
|
119
|
+
private static initInput;
|
|
120
|
+
/**
|
|
121
|
+
* Default initialisation function for conditions requiring 2 inputs
|
|
122
|
+
*/
|
|
123
|
+
private static init2Input;
|
|
124
|
+
/**
|
|
125
|
+
* Default initialisation function for date conditions
|
|
126
|
+
*/
|
|
127
|
+
private static initDate;
|
|
128
|
+
private static initNoValue;
|
|
129
|
+
private static init2Date;
|
|
130
|
+
/**
|
|
131
|
+
* Default function for select elements to validate condition
|
|
132
|
+
*/
|
|
133
|
+
private static isInputValidSelect;
|
|
134
|
+
/**
|
|
135
|
+
* Default function for input and date elements to validate condition
|
|
136
|
+
*/
|
|
137
|
+
private static isInputValidInput;
|
|
138
|
+
/**
|
|
139
|
+
* Default function for getting select conditions
|
|
140
|
+
*/
|
|
141
|
+
private static inputValueSelect;
|
|
142
|
+
/**
|
|
143
|
+
* Default function for getting input conditions
|
|
144
|
+
*/
|
|
145
|
+
private static inputValueInput;
|
|
146
|
+
/**
|
|
147
|
+
* Function that is run on each element as a call back when a search should be triggered
|
|
148
|
+
*/
|
|
149
|
+
private static updateListener;
|
|
150
|
+
static dateConditions: {
|
|
151
|
+
[keys: string]: ICondition;
|
|
152
|
+
};
|
|
153
|
+
static momentDateConditions: {
|
|
154
|
+
[keys: string]: ICondition;
|
|
155
|
+
};
|
|
156
|
+
static luxonDateConditions: {
|
|
157
|
+
[keys: string]: ICondition;
|
|
158
|
+
};
|
|
159
|
+
static numConditions: {
|
|
160
|
+
[keys: string]: ICondition;
|
|
161
|
+
};
|
|
162
|
+
static numFmtConditions: {
|
|
163
|
+
[keys: string]: ICondition;
|
|
164
|
+
};
|
|
165
|
+
static stringConditions: {
|
|
166
|
+
[keys: string]: ICondition;
|
|
167
|
+
};
|
|
168
|
+
static arrayConditions: {
|
|
169
|
+
[keys: string]: ICondition;
|
|
170
|
+
};
|
|
171
|
+
private static defaults;
|
|
172
|
+
/**
|
|
173
|
+
* Adds the left button to the criteria
|
|
174
|
+
*/
|
|
175
|
+
updateArrows(hasSiblings?: boolean, redraw?: boolean): void;
|
|
176
|
+
/**
|
|
177
|
+
* Destroys the criteria, removing listeners and container from the dom
|
|
178
|
+
*/
|
|
179
|
+
destroy(): void;
|
|
180
|
+
/**
|
|
181
|
+
* Passes in the data for the row and compares it against this single criteria
|
|
182
|
+
*
|
|
183
|
+
* @param rowData The data for the row to be compared
|
|
184
|
+
* @returns boolean Whether the criteria has passed
|
|
185
|
+
*/
|
|
186
|
+
search(rowData: any[], rowIdx: number): boolean;
|
|
187
|
+
/**
|
|
188
|
+
* Gets the details required to rebuild the criteria
|
|
189
|
+
*/
|
|
190
|
+
getDetails(deFormatDates?: boolean): IDetails;
|
|
191
|
+
/**
|
|
192
|
+
* Getter for the node for the container of the criteria
|
|
193
|
+
*
|
|
194
|
+
* @returns JQuery<HTMLElement> the node for the container
|
|
195
|
+
*/
|
|
196
|
+
getNode(): JQuery<HTMLElement>;
|
|
197
|
+
/**
|
|
198
|
+
* Populates the criteria data, condition and value(s) as far as has been selected
|
|
199
|
+
*/
|
|
200
|
+
populate(): void;
|
|
201
|
+
/**
|
|
202
|
+
* Rebuilds the criteria based upon the details passed in
|
|
203
|
+
*
|
|
204
|
+
* @param loadedCriteria the details required to rebuild the criteria
|
|
205
|
+
*/
|
|
206
|
+
rebuild(loadedCriteria: IDetails): void;
|
|
207
|
+
/**
|
|
208
|
+
* Sets the listeners for the criteria
|
|
209
|
+
*/
|
|
210
|
+
setListeners(): void;
|
|
211
|
+
/**
|
|
212
|
+
* Adjusts the criteria to make SearchBuilder responsive
|
|
213
|
+
*/
|
|
214
|
+
private _adjustCriteria;
|
|
215
|
+
/**
|
|
216
|
+
* Builds the elements of the dom together
|
|
217
|
+
*/
|
|
218
|
+
private _buildCriteria;
|
|
219
|
+
/**
|
|
220
|
+
* Clears the condition select element
|
|
221
|
+
*/
|
|
222
|
+
private _clearCondition;
|
|
223
|
+
/**
|
|
224
|
+
* Clears the value elements
|
|
225
|
+
*/
|
|
226
|
+
private _clearValue;
|
|
227
|
+
/**
|
|
228
|
+
* Gets the options for the column
|
|
229
|
+
*
|
|
230
|
+
* @returns {object} The options for the column
|
|
231
|
+
*/
|
|
232
|
+
private _getOptions;
|
|
233
|
+
/**
|
|
234
|
+
* Populates the condition dropdown
|
|
235
|
+
*/
|
|
236
|
+
private _populateCondition;
|
|
237
|
+
/**
|
|
238
|
+
* Populates the data select element
|
|
239
|
+
*/
|
|
240
|
+
private _populateData;
|
|
241
|
+
/**
|
|
242
|
+
* Populates the Value select element
|
|
243
|
+
*
|
|
244
|
+
* @param loadedCriteria optional, used to reload criteria from predefined filters
|
|
245
|
+
*/
|
|
246
|
+
private _populateValue;
|
|
247
|
+
/**
|
|
248
|
+
* Provides throttling capabilities to SearchBuilder without having to use dt's _fnThrottle function
|
|
249
|
+
* This is because that function is not quite suitable for our needs as it runs initially rather than waiting
|
|
250
|
+
*
|
|
251
|
+
* @param args arguments supplied to the throttle function
|
|
252
|
+
* @returns Function that is to be run that implements the throttling
|
|
253
|
+
*/
|
|
254
|
+
private _throttle;
|
|
255
|
+
}
|
package/types/group.d.ts
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/// <reference types="jquery" />
|
|
2
|
+
/// <reference types="datatables.net" />
|
|
3
|
+
import Criteria, * as criteriaType from './criteria';
|
|
4
|
+
import * as builderType from './searchBuilder';
|
|
5
|
+
export interface IClassses {
|
|
6
|
+
add: string;
|
|
7
|
+
button: string;
|
|
8
|
+
clearGroup: string;
|
|
9
|
+
greyscale: string;
|
|
10
|
+
group: string;
|
|
11
|
+
inputButton: string;
|
|
12
|
+
logic: string;
|
|
13
|
+
logicContainer: string;
|
|
14
|
+
}
|
|
15
|
+
export interface IDom {
|
|
16
|
+
add: JQuery<HTMLElement>;
|
|
17
|
+
clear: JQuery<HTMLElement>;
|
|
18
|
+
container: JQuery<HTMLElement>;
|
|
19
|
+
logic: JQuery<HTMLElement>;
|
|
20
|
+
logicContainer: JQuery<HTMLElement>;
|
|
21
|
+
}
|
|
22
|
+
export interface IS {
|
|
23
|
+
criteria: ISCriteria[];
|
|
24
|
+
depth: number;
|
|
25
|
+
dt: any;
|
|
26
|
+
index: number;
|
|
27
|
+
isChild: boolean;
|
|
28
|
+
logic: string;
|
|
29
|
+
opts: builderType.IDefaults;
|
|
30
|
+
preventRedraw: boolean;
|
|
31
|
+
toDrop: Criteria;
|
|
32
|
+
topGroup: JQuery<HTMLElement>;
|
|
33
|
+
}
|
|
34
|
+
export interface ICriteria {
|
|
35
|
+
criteria: Array<IDetails | criteriaType.IDetails>;
|
|
36
|
+
index: number;
|
|
37
|
+
}
|
|
38
|
+
export interface ICriteriaDetails {
|
|
39
|
+
condition?: string;
|
|
40
|
+
data?: string;
|
|
41
|
+
logic?: string;
|
|
42
|
+
value?: string[];
|
|
43
|
+
}
|
|
44
|
+
export interface ISCriteria {
|
|
45
|
+
criteria: Group | Criteria;
|
|
46
|
+
index: number;
|
|
47
|
+
logic?: string;
|
|
48
|
+
}
|
|
49
|
+
export interface IDetails {
|
|
50
|
+
criteria?: ICriteriaDetails[];
|
|
51
|
+
index?: number;
|
|
52
|
+
logic?: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Sets the value of jQuery for use in the file
|
|
56
|
+
*
|
|
57
|
+
* @param jq the instance of jQuery to be set
|
|
58
|
+
*/
|
|
59
|
+
export declare function setJQuery(jq: any): void;
|
|
60
|
+
/**
|
|
61
|
+
* The Group class is used within SearchBuilder to represent a group of criteria
|
|
62
|
+
*/
|
|
63
|
+
export default class Group {
|
|
64
|
+
private static version;
|
|
65
|
+
private static classes;
|
|
66
|
+
private static defaults;
|
|
67
|
+
classes: IClassses;
|
|
68
|
+
dom: IDom;
|
|
69
|
+
c: builderType.IDefaults;
|
|
70
|
+
s: IS;
|
|
71
|
+
constructor(table: any, opts: builderType.IDefaults, topGroup: JQuery<HTMLElement>, index?: number, isChild?: boolean, depth?: number);
|
|
72
|
+
/**
|
|
73
|
+
* Destroys the groups buttons, clears the internal criteria and removes it from the dom
|
|
74
|
+
*/
|
|
75
|
+
destroy(): void;
|
|
76
|
+
/**
|
|
77
|
+
* Gets the details required to rebuild the group
|
|
78
|
+
*/
|
|
79
|
+
getDetails(deFormatDates?: boolean): IDetails | {};
|
|
80
|
+
/**
|
|
81
|
+
* Getter for the node for the container of the group
|
|
82
|
+
*
|
|
83
|
+
* @returns Node for the container of the group
|
|
84
|
+
*/
|
|
85
|
+
getNode(): JQuery<HTMLElement>;
|
|
86
|
+
/**
|
|
87
|
+
* Rebuilds the group based upon the details passed in
|
|
88
|
+
*
|
|
89
|
+
* @param loadedDetails the details required to rebuild the group
|
|
90
|
+
*/
|
|
91
|
+
rebuild(loadedDetails: IDetails | criteriaType.IDetails): void;
|
|
92
|
+
/**
|
|
93
|
+
* Redraws the Contents of the searchBuilder Groups and Criteria
|
|
94
|
+
*/
|
|
95
|
+
redrawContents(): void;
|
|
96
|
+
/**
|
|
97
|
+
* Resizes the logic button only rather than the entire dom.
|
|
98
|
+
*/
|
|
99
|
+
redrawLogic(): void;
|
|
100
|
+
/**
|
|
101
|
+
* Search method, checking the row data against the criteria in the group
|
|
102
|
+
*
|
|
103
|
+
* @param rowData The row data to be compared
|
|
104
|
+
* @returns boolean The result of the search
|
|
105
|
+
*/
|
|
106
|
+
search(rowData: any[], rowIdx: number): boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Locates the groups logic button to the correct location on the page
|
|
109
|
+
*/
|
|
110
|
+
setupLogic(): void;
|
|
111
|
+
/**
|
|
112
|
+
* Sets listeners on the groups elements
|
|
113
|
+
*/
|
|
114
|
+
setListeners(): void;
|
|
115
|
+
/**
|
|
116
|
+
* Adds a criteria to the group
|
|
117
|
+
*
|
|
118
|
+
* @param crit Instance of Criteria to be added to the group
|
|
119
|
+
*/
|
|
120
|
+
addCriteria(crit?: Criteria, redraw?: boolean): void;
|
|
121
|
+
/**
|
|
122
|
+
* Checks the group to see if it has any filled criteria
|
|
123
|
+
*/
|
|
124
|
+
checkFilled(): boolean;
|
|
125
|
+
/**
|
|
126
|
+
* Gets the count for the number of criteria in this group and any sub groups
|
|
127
|
+
*/
|
|
128
|
+
count(): number;
|
|
129
|
+
/**
|
|
130
|
+
* Rebuilds a sub group that previously existed
|
|
131
|
+
*
|
|
132
|
+
* @param loadedGroup The details of a group within this group
|
|
133
|
+
*/
|
|
134
|
+
private _addPrevGroup;
|
|
135
|
+
/**
|
|
136
|
+
* Rebuilds a criteria of this group that previously existed
|
|
137
|
+
*
|
|
138
|
+
* @param loadedCriteria The details of a criteria within the group
|
|
139
|
+
*/
|
|
140
|
+
private _addPrevCriteria;
|
|
141
|
+
/**
|
|
142
|
+
* Checks And the criteria using AND logic
|
|
143
|
+
*
|
|
144
|
+
* @param rowData The row data to be checked against the search criteria
|
|
145
|
+
* @returns boolean The result of the AND search
|
|
146
|
+
*/
|
|
147
|
+
private _andSearch;
|
|
148
|
+
/**
|
|
149
|
+
* Checks And the criteria using OR logic
|
|
150
|
+
*
|
|
151
|
+
* @param rowData The row data to be checked against the search criteria
|
|
152
|
+
* @returns boolean The result of the OR search
|
|
153
|
+
*/
|
|
154
|
+
private _orSearch;
|
|
155
|
+
/**
|
|
156
|
+
* Removes a criteria from the group
|
|
157
|
+
*
|
|
158
|
+
* @param criteria The criteria instance to be removed
|
|
159
|
+
*/
|
|
160
|
+
private _removeCriteria;
|
|
161
|
+
/**
|
|
162
|
+
* Sets the listeners in group for a criteria
|
|
163
|
+
*
|
|
164
|
+
* @param criteria The criteria for the listeners to be set on
|
|
165
|
+
*/
|
|
166
|
+
private _setCriteriaListeners;
|
|
167
|
+
/**
|
|
168
|
+
* Set's the listeners for the group clear button
|
|
169
|
+
*/
|
|
170
|
+
private _setClearListener;
|
|
171
|
+
/**
|
|
172
|
+
* Sets listeners for sub groups of this group
|
|
173
|
+
*
|
|
174
|
+
* @param group The sub group that the listeners are to be set on
|
|
175
|
+
*/
|
|
176
|
+
private _setGroupListeners;
|
|
177
|
+
/**
|
|
178
|
+
* Sets up the Group instance, setting listeners and appending elements
|
|
179
|
+
*/
|
|
180
|
+
private _setup;
|
|
181
|
+
/**
|
|
182
|
+
* Sets the listener for the logic button
|
|
183
|
+
*/
|
|
184
|
+
private _setLogicListener;
|
|
185
|
+
/**
|
|
186
|
+
* Toggles the logic for the group
|
|
187
|
+
*/
|
|
188
|
+
private _toggleLogic;
|
|
189
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/// <reference types="jquery" />
|
|
2
|
+
/// <reference types="datatables.net" />
|
|
3
|
+
/**
|
|
4
|
+
* Sets the value of jQuery for use in the file
|
|
5
|
+
*
|
|
6
|
+
* @param jq the instance of jQuery to be set
|
|
7
|
+
*/
|
|
8
|
+
export declare function setJQuery(jq: any): void;
|
|
9
|
+
import * as criteriaType from './criteria';
|
|
10
|
+
import Group from './group';
|
|
11
|
+
export interface IDetails {
|
|
12
|
+
criteria: Group[];
|
|
13
|
+
logic: string;
|
|
14
|
+
}
|
|
15
|
+
export interface IClasses {
|
|
16
|
+
button: string;
|
|
17
|
+
clearAll: string;
|
|
18
|
+
container: string;
|
|
19
|
+
inputButton: string;
|
|
20
|
+
title: string;
|
|
21
|
+
titleRow: string;
|
|
22
|
+
}
|
|
23
|
+
export interface IDefaults {
|
|
24
|
+
columns: number[] | boolean;
|
|
25
|
+
conditions: {
|
|
26
|
+
[keys: string]: {
|
|
27
|
+
[keys: string]: criteriaType.ICondition;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
depthLimit: boolean | number;
|
|
31
|
+
enterSearch: boolean;
|
|
32
|
+
filterChanged: (count: number, text: string) => void;
|
|
33
|
+
greyscale: boolean;
|
|
34
|
+
i18n: II18n;
|
|
35
|
+
logic: string;
|
|
36
|
+
orthogonal: criteriaType.IOrthogonal;
|
|
37
|
+
preDefined: boolean | IDetails;
|
|
38
|
+
}
|
|
39
|
+
export interface IDom {
|
|
40
|
+
clearAll: JQuery<HTMLElement>;
|
|
41
|
+
container: JQuery<HTMLElement>;
|
|
42
|
+
title: JQuery<HTMLElement>;
|
|
43
|
+
titleRow: JQuery<HTMLElement>;
|
|
44
|
+
topGroup: JQuery<HTMLElement>;
|
|
45
|
+
}
|
|
46
|
+
export interface II18n {
|
|
47
|
+
add: string;
|
|
48
|
+
button: {
|
|
49
|
+
0: string;
|
|
50
|
+
_: string;
|
|
51
|
+
};
|
|
52
|
+
clearAll: string;
|
|
53
|
+
condition: string;
|
|
54
|
+
conditions?: {
|
|
55
|
+
[s: string]: {
|
|
56
|
+
[t: string]: string;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
data: string;
|
|
60
|
+
delete: string;
|
|
61
|
+
deleteTitle: string;
|
|
62
|
+
left: string;
|
|
63
|
+
leftTitle: string;
|
|
64
|
+
logicAnd: string;
|
|
65
|
+
logicOr: string;
|
|
66
|
+
right: string;
|
|
67
|
+
rightTitle: string;
|
|
68
|
+
title: {
|
|
69
|
+
0: string;
|
|
70
|
+
_: string;
|
|
71
|
+
};
|
|
72
|
+
value: string;
|
|
73
|
+
valueJoiner: string;
|
|
74
|
+
}
|
|
75
|
+
export interface IS {
|
|
76
|
+
dt: any;
|
|
77
|
+
opts: IDefaults;
|
|
78
|
+
search: (settings: any, searchData: any, dataIndex: any, origData: any) => boolean;
|
|
79
|
+
topGroup: Group;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* SearchBuilder class for DataTables.
|
|
83
|
+
* Allows for complex search queries to be constructed and implemented on a DataTable
|
|
84
|
+
*/
|
|
85
|
+
export default class SearchBuilder {
|
|
86
|
+
private static version;
|
|
87
|
+
private static classes;
|
|
88
|
+
private static defaults;
|
|
89
|
+
classes: IClasses;
|
|
90
|
+
dom: IDom;
|
|
91
|
+
c: IDefaults;
|
|
92
|
+
s: IS;
|
|
93
|
+
constructor(builderSettings: any, opts: IDefaults);
|
|
94
|
+
/**
|
|
95
|
+
* Gets the details required to rebuild the SearchBuilder as it currently is
|
|
96
|
+
*/
|
|
97
|
+
getDetails(deFormatDates?: boolean): IDetails | {};
|
|
98
|
+
/**
|
|
99
|
+
* Getter for the node of the container for the searchBuilder
|
|
100
|
+
*
|
|
101
|
+
* @returns JQuery<HTMLElement> the node of the container
|
|
102
|
+
*/
|
|
103
|
+
getNode(): JQuery<HTMLElement>;
|
|
104
|
+
/**
|
|
105
|
+
* Rebuilds the SearchBuilder to a state that is provided
|
|
106
|
+
*
|
|
107
|
+
* @param details The details required to perform a rebuild
|
|
108
|
+
*/
|
|
109
|
+
rebuild(details: any): SearchBuilder;
|
|
110
|
+
/**
|
|
111
|
+
* Applies the defaults to preDefined criteria
|
|
112
|
+
*
|
|
113
|
+
* @param preDef the array of criteria to be processed.
|
|
114
|
+
*/
|
|
115
|
+
private _applyPreDefDefaults;
|
|
116
|
+
/**
|
|
117
|
+
* Set's up the SearchBuilder
|
|
118
|
+
*/
|
|
119
|
+
private _setUp;
|
|
120
|
+
private _collapseArray;
|
|
121
|
+
/**
|
|
122
|
+
* Updates the title of the SearchBuilder
|
|
123
|
+
*
|
|
124
|
+
* @param count the number of filters in the SearchBuilder
|
|
125
|
+
*/
|
|
126
|
+
private _updateTitle;
|
|
127
|
+
/**
|
|
128
|
+
* Builds all of the dom elements together
|
|
129
|
+
*/
|
|
130
|
+
private _build;
|
|
131
|
+
/**
|
|
132
|
+
* Checks if the clearAll button should be added or not
|
|
133
|
+
*/
|
|
134
|
+
private _checkClear;
|
|
135
|
+
/**
|
|
136
|
+
* Update the count in the title/button
|
|
137
|
+
*
|
|
138
|
+
* @param count Number of filters applied
|
|
139
|
+
*/
|
|
140
|
+
private _filterChanged;
|
|
141
|
+
/**
|
|
142
|
+
* Set the listener for the clear button
|
|
143
|
+
*/
|
|
144
|
+
private _setClearListener;
|
|
145
|
+
/**
|
|
146
|
+
* Set the listener for the Redraw event
|
|
147
|
+
*/
|
|
148
|
+
private _setRedrawListener;
|
|
149
|
+
/**
|
|
150
|
+
* Sets listeners to check whether clearAll should be added or removed
|
|
151
|
+
*/
|
|
152
|
+
private _setEmptyListener;
|
|
153
|
+
}
|
package/types/types.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/// <reference types="jquery" />
|
|
2
|
+
/// <reference types="datatables.net"/>
|
|
3
|
+
|
|
4
|
+
import {IDefaults, IDetails} from './searchBuilder';
|
|
5
|
+
|
|
6
|
+
declare namespace DataTables {
|
|
7
|
+
|
|
8
|
+
interface Settings {
|
|
9
|
+
searchBuilder?: boolean | string[] | IDefaults | IDefaults[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface LanguageSettings {
|
|
13
|
+
searchBuilder?: {}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface Api<T> {
|
|
17
|
+
searchBuilder: SearchBuilderGlobalApi;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface SearchBuilderGlobalApi {
|
|
21
|
+
/**
|
|
22
|
+
* Returns the node of the SearchBuilder Container
|
|
23
|
+
*/
|
|
24
|
+
container(): JQuery<HTMLElement>;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Gets the details of the current SearchBuilder setup
|
|
28
|
+
*/
|
|
29
|
+
getDetails(): IDetails;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Rebuild the search to a given state.
|
|
33
|
+
*
|
|
34
|
+
* @param state Object of the same structue that is returned from searchBuilder.getDetails().
|
|
35
|
+
* This contains all of the details needed to rebuild the state.
|
|
36
|
+
* @returns self for chaining
|
|
37
|
+
*/
|
|
38
|
+
rebuild(state: IDetails): Api<any>;
|
|
39
|
+
}
|
|
40
|
+
}
|