Drag and drop in React Query builder component
12 Jun 202411 minutes to read
The Query Builder provides the functionality to reposition rules or groups within the component effortlessly. This enhancement provides a more intuitive and flexible way to construct and modify queries. You can use allowDragAndDrop
to perform drag and drop functionality. And we have events support for drag and drop features that, indicates the dragStart
, drag
and drop
actions.
import { QueryBuilderComponent } from '@syncfusion/ej2-react-querybuilder';
import * as React from 'react';
import * as ReactDom from 'react-dom';
// @ts-ignore
import { employeeData } from '../datasource.ts';
function App() {
let qryBldrObj;
let dateOperators = [
{ value: 'equal', key: 'Equal' },
{ value: 'greaterthan', key: 'Greater Than' },
{ value: 'greaterthanorequal', key: 'Greater Than Or Equal' },
{ value: 'lessthan', key: 'Less Than' },
{ value: 'lessthanorequal', key: 'Less Than Or Equal' },
{ value: 'notequal', key: 'Not Equal' },
{ value: 'between', key: 'Between' },
{ value: 'notbetween', key: 'Not Between' }
];
let boolOperators = [
{ value: 'equal', key: 'Equal' },
];
let columnData = [
{ field: "EmployeeID", label: "Employee ID", type: "number" },
{ field: "FirstName", label: "First Name", type: "string" },
{ field: "LastName", label: "Last Name", type: "string" },
{ field: "Age", label: "Age", type: "number" },
{ field: "IsDeveloper", label: "Is Developer", type: "boolean", operators: boolOperators },
{ field: "PrimaryFramework", label: "Primary Framework", type: "string" },
{ field: "HireDate", label: "Hire Date", type: "date", format: "MM/dd/yyyy", operators: dateOperators },
{ field: "Country", label: "Country", type: "string" }
];
let importRules = {
condition: "and",
rules: [
{ label: "First Name", field: "FirstName", type: "string", operator: "startswith", value: "Andre" },
{ label: "Last Name", field: "LastName", type: "string", operator: "in", value: ['Davolio', 'Buchanan'] },
{ label: "Age", field: "Age", type: "number", operator: "greaterthan", value: 29 },
{
condition: "or", rules: [
{ label: "Is Developer", field: "IsDeveloper", type: "boolean", operator: "equal", value: true },
{ label: "Primary Framework", field: "PrimaryFramework", type: "string", operator: "equal", value: "React" }
]
},
{ label: "Hire Date", field: "HireDate", type: "date", operator: "between", value: ["11/22/2023", "11/30/2023"] },
]
};
return (<div>
<QueryBuilderComponent width='100%' dataSource={employeeData} ref={(scope) => { qryBldrObj = scope; }} rule={importRules} columns={columnData} allowDragAndDrop={true} />
</div>);
}
export default App;
ReactDom.render(<App />, document.getElementById('querybuilder'));
import { ColumnsModel, QueryBuilderComponent, RuleModel } from '@syncfusion/ej2-react-querybuilder';
import * as React from 'react';
import * as ReactDom from 'react-dom';
// @ts-ignore
import { employeeData } from '../datasource.ts';
function App() {
let qryBldrObj: QueryBuilderComponent;
let dateOperators: any = [
{ value: 'equal', key: 'Equal' },
{ value: 'greaterthan', key: 'Greater Than' },
{ value: 'greaterthanorequal', key: 'Greater Than Or Equal' },
{ value: 'lessthan', key: 'Less Than' },
{ value: 'lessthanorequal', key: 'Less Than Or Equal' },
{ value: 'notequal', key: 'Not Equal' },
{ value: 'between', key: 'Between' },
{ value: 'notbetween', key: 'Not Between' }
];
let boolOperators: any = [
{ value: 'equal', key: 'Equal' },
];
let columns: ColumnsModel[] = [
{ field: "EmployeeID", label: "Employee ID", type: "number" },
{ field: "FirstName", label: "First Name", type: "string" },
{ field: "LastName", label: "Last Name", type: "string" },
{ field: "Age", label: "Age", type: "number" },
{ field: "IsDeveloper", label: "Is Developer", type: "boolean", operators: boolOperators },
{ field: "PrimaryFramework", label: "Primary Framework", type: "string" },
{ field: "HireDate", label: "Hire Date", type: "date", format: "MM/dd/yyyy", operators: dateOperators },
{ field: "Country", label: "Country", type: "string" }
]
let importRules: RuleModel = {
condition: "and",
rules: [
{ label: "First Name", field: "FirstName", type: "string", operator: "startswith", value: "Andre" },
{ label: "Last Name", field: "LastName", type: "string", operator: "in", value: ['Davolio', 'Buchanan'] },
{ label: "Age", field: "Age", type: "number", operator: "greaterthan", value: 29 },
{
condition: "or", rules: [
{ label: "Is Developer", field: "IsDeveloper", type: "boolean", operator: "equal", value: true },
{ label: "Primary Framework", field: "PrimaryFramework", type: "string", operator: "equal", value: "React" }
]
},
{ label: "Hire Date", field: "HireDate", type: "date", operator: "between", value: ["11/22/2023", "11/30/2023"] },
],
};
return (
<div>
<QueryBuilderComponent width='100%' dataSource={employeeData} ref={(scope) => { qryBldrObj = scope as QueryBuilderComponent; }} columns={columns} rule={importRules} allowDragAndDrop={true}/>
</div>
);
}
export default App;
ReactDom.render(<App />,document.getElementById('querybuilder'));