Similar question to https://www.syncfusion.com/forums/165008/how-to-compare-to-another-column but in React.
Also is there a possibility to add a dropdown between the column selector and the operator selector that allows the selection between setting a value (normal use) or comparing to other columns?
The use case is that numerical columns can be compared between them while maintaining the option of comparing with a defined number.
Thanks!
|
this.filter = [
{
field: 'Expense',
label: 'Expense',
type: 'number',
},
{
field: 'Income',
label: 'Income',
type: 'string',
template: {
create: () => {
this.elem = document.createElement('input');
this.elem.setAttribute('type', 'text');
return this.elem;
},
destroy: (args) => {
this.dropDownObj = getComponent(
document.getElementById(args.elementId),
'dropdownlist'
);
if (this.dropDownObj) {
this.dropDownObj.destroy();
}
},
write: (args) => {
let column = [];
for (let x in this.filter) column.push(this.filter[x].field);
let dropDownObj = new DropDownList({
dataSource: column,
value: args.values,
change: (e) => {
this.qryBldrObj.notifyChange(e.itemData.value, e.element);
},
});
dropDownObj.appendTo('#' + args.elements.id);
},
},
operators: [
{ key: 'Equal', value: 'equal' },
{ key: 'Not equal', value: 'notequal' },
{ key: 'Greater than', value: 'greaterthan' },
{ key: 'Less than', value: 'lessthan' },
{ key: 'Less than or equal', value: 'lessthanorequal' },
{ key: 'Greater than or equal', value: 'greaterthanorequal' },
],
},
{ field: 'Description', label: 'Description', type: 'string' },
];
}
updateRule(args) {
this.txtAreaElem = document.getElementById('ruleContent');
if (this.radioButton.checked) {
this.txtAreaElem.value = this.qryBldrObj.getSqlFromRules(args.rule);
} else {
this.txtAreaElem.value = JSON.stringify(args.rule, null, 4);
}
}
<QueryBuilderComponent
dataSource={expenseData}
columns={this.filter}
width="100%"
rule={this.importRules}
ref={(scope) => {
this.qryBldrObj = scope;
}}
created={this.onCreated.bind(this)}
ruleChange={this.updateRule.bind(this)}
></QueryBuilderComponent> |
Hi,
Thanks for the swift response.
I am trying the rule template method but I am getting an error that seems very obscure. All my tests have pointed out that this has nothing to do with the template class but what happens between changing the value of the column to one that has a template.
The log stops after the actionBegin method. What can I log is the following:
{
"requestType": "template-initialize",
"ruleID": "querybuilder_group1_rule0",
"action": "field",
"fields": {
"text": "label",
"value": "field"
},
"rule": {
"condition": "and",
"rules": [],
"field": "waitlist_count",
"label": "Waitlist Count",
"type": "number",
"value": 0,
"operator": "equal"
},
"name": "actionBegin"
}
The error is:
Uncaught TypeError: str.match is not a function
at evalExp (template.js:83:1)
at compile (template.js:63:1)
at Object.Engine.compile (template-engine.js:155:1)
at compile (template-engine.js:28:1)
at QueryBuilderComponent.QueryBuilder.templateParser (query-builder.js:3330:1)
at QueryBuilderComponent.QueryBuilder.appendRuleElem (query-builder.js:563:1)
at QueryBuilderComponent.QueryBuilder.templateChange (query-builder.js:1219:1)
at QueryBuilderComponent.QueryBuilder.changeField (query-builder.js:1382:1)
at Observer.notify (observer.js:101:1)
at DropDownList.Base.trigger (base.js:190:1)
at DropDownList.detachChangeEvent (drop-down-list.js:1173:1)
at DropDownList.onChangeEvent (drop-down-list.js:1109:1)
at DropDownList.setSelectOptions (drop-down-list.js:1023:1)
at Observer.<anonymous> (drop-down-list.js:930:1)
at Observer.notify (observer.js:86:1)
at DropDownList.Base.trigger (base.js:190:1)
at DropDownList.updateSelectedItem (drop-down-list.js:923:1)
at DropDownList.setSelection (drop-down-list.js:999:1)
at DropDownList.onMouseClick (drop-down-list.js:549:1)
Please could you let me know if this is a known issue, or maybe a working sample would help.
|
Package.json
"dependencies": {
"@syncfusion/ej2-angular-navigations ": "*",
"@syncfusion/ej2-base": "*",
"@syncfusion/ej2-data": "*",
. . . . . . . .
. . . . . . . .
}
|