|
| 1 | +<template> |
| 2 | + <div class="container"> |
| 3 | + <div> |
| 4 | + <ejs-button cssClass="button" @click="importRules">Import Rules</ejs-button> |
| 5 | + <ejs-button cssClass="button" @click="exportRules">Export Rules</ejs-button> |
| 6 | + </div> |
| 7 | + <ejs-querybuilder :dataSource="dataSource" ref="querybuilder" /> |
| 8 | + </div> |
| 9 | +</template> |
| 10 | +<script> |
| 11 | +import { QueryBuilderComponent, QueryLibrary, QueryBuilder } from "@syncfusion/ej2-vue-querybuilder"; |
| 12 | +import { ButtonComponent } from "@syncfusion/ej2-vue-buttons"; |
| 13 | +QueryBuilder.Inject(QueryLibrary); |
| 14 | +
|
| 15 | +// #region hardwareData |
| 16 | +var hardwareData = [{ |
| 17 | + 'TaskID': 1, |
| 18 | + 'Name': 'Lenovo Yoga', |
| 19 | + 'Category': 'Laptop', |
| 20 | + 'SerialNo': 'CB27932009', |
| 21 | + 'InvoiceNo': 'INV-2878', |
| 22 | + 'Status': 'Assigned' |
| 23 | +}, |
| 24 | +{ |
| 25 | + 'TaskID': 2, |
| 26 | + 'Name': 'Acer Aspire', |
| 27 | + 'Category': 'Others', |
| 28 | + 'SerialNo': 'CB35728290', |
| 29 | + 'InvoiceNo': 'INV-3456', |
| 30 | + 'Status': 'In-repair' |
| 31 | +}, |
| 32 | +{ |
| 33 | + 'TaskID': 3, |
| 34 | + 'Name': 'Apple MacBook', |
| 35 | + 'Category': 'Laptop', |
| 36 | + 'SerialNo': 'CB35628728', |
| 37 | + 'InvoiceNo': 'INV-2763', |
| 38 | + 'Status': 'In-repair' |
| 39 | +}]; |
| 40 | +// #endregion |
| 41 | +
|
| 42 | +export default { |
| 43 | + components: { |
| 44 | + "ejs-querybuilder": QueryBuilderComponent, |
| 45 | + "ejs-button": ButtonComponent |
| 46 | + }, |
| 47 | + data() { |
| 48 | + return { |
| 49 | + dataSource: hardwareData, |
| 50 | + rule: { |
| 51 | + 'condition': 'or', |
| 52 | + 'rules': [{ |
| 53 | + 'label': 'Category', |
| 54 | + 'field': 'Category', |
| 55 | + 'operator': 'equal', |
| 56 | + 'value': 'Laptop' |
| 57 | + }, |
| 58 | + { |
| 59 | + 'condition': 'and', |
| 60 | + 'rules': [{ |
| 61 | + 'label': 'Status', |
| 62 | + 'field': 'Status', |
| 63 | + 'operator': 'notequal', |
| 64 | + 'value': 'Pending' |
| 65 | + }, |
| 66 | + { |
| 67 | + 'label': 'Task ID', |
| 68 | + 'field': 'TaskID', |
| 69 | + 'operator': 'equal', |
| 70 | + 'value': 5675 |
| 71 | + }] |
| 72 | + }] |
| 73 | + } |
| 74 | + }; |
| 75 | + }, |
| 76 | + methods: { |
| 77 | + importRules() { |
| 78 | + this.$refs.querybuilder.ej2Instances.setRules(this.rule); |
| 79 | +
|
| 80 | + /* this.$refs.querybuilder.ej2Instances.setRulesFromSql( |
| 81 | + "TaskID = 1 and Status LIKE ('Assigned%')" |
| 82 | + ); */ |
| 83 | +
|
| 84 | + /* this.$refs.querybuilder.ej2Instances.setParameterizedSql( |
| 85 | + { |
| 86 | + sql: '(Category IN (?,?) OR TaskID IN (?,?))', |
| 87 | + params: ['Laptop', 'Others', 1, 2] |
| 88 | + }); */ |
| 89 | + /* this.$refs.querybuilder.ej2Instances.setParameterizedNamedSql( |
| 90 | + { |
| 91 | + sql: '(Category IN (:Category_1,:Category_2) OR TaskID IN (:TaskID_1,:TaskID_2))', |
| 92 | + params: { "Category_1": "Laptop", "Category_2": "Others", "TaskID_1": 1, "TaskID_2": 2 } |
| 93 | + } |
| 94 | + ); */ |
| 95 | + }, |
| 96 | + exportRules() { |
| 97 | + console.log( |
| 98 | +
|
| 99 | + this.$refs.querybuilder.ej2Instances.getValidRules() |
| 100 | +
|
| 101 | + /* this.$refs.querybuilder.ej2Instances.getSqlFromRules( |
| 102 | + this.$refs.querybuilder.ej2Instances.getValidRules()) */ |
| 103 | +
|
| 104 | + /* this.$refs.querybuilder.ej2Instances.getParameterizedSql( |
| 105 | + this.$refs.querybuilder.ej2Instances.getValidRules()) */ |
| 106 | +
|
| 107 | + /* this.$refs.querybuilder.ej2Instances.getParameterizedNamedSql( |
| 108 | + this.$refs.querybuilder.ej2Instances.getValidRules()) */ |
| 109 | + ); |
| 110 | + } |
| 111 | + } |
| 112 | +}; |
| 113 | +</script> |
| 114 | + |
| 115 | +<style> |
| 116 | +@import "../node_modules/@syncfusion/ej2-base/styles/material.css"; |
| 117 | +@import "../node_modules/@syncfusion/ej2-buttons/styles/material.css"; |
| 118 | +@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css"; |
| 119 | +@import "../node_modules/@syncfusion/ej2-dropdowns/styles/material.css"; |
| 120 | +@import "../node_modules/@syncfusion/ej2-inputs/styles/material.css"; |
| 121 | +@import "../node_modules/@syncfusion/ej2-lists/styles/material.css"; |
| 122 | +@import "../node_modules/@syncfusion/ej2-popups/styles/material.css"; |
| 123 | +@import "../node_modules/@syncfusion/ej2-calendars/styles/material.css"; |
| 124 | +@import "../node_modules/@syncfusion/ej2-vue-querybuilder/styles/material.css"; |
| 125 | +
|
| 126 | +.container { |
| 127 | + display: flex; |
| 128 | + flex-direction: column; |
| 129 | + align-items: center; |
| 130 | + width: 95%; |
| 131 | + margin: 0 auto; |
| 132 | + position: absolute; |
| 133 | + top: 20px; |
| 134 | + left: 50%; |
| 135 | + transform: translateX(-50%); |
| 136 | +} |
| 137 | +
|
| 138 | +.button { |
| 139 | + margin: 20px; |
| 140 | +} |
| 141 | +</style> |
0 commit comments