|
[Home.controller]
public IActionResult GetData([FromBody]DataClass dm)
{
// filter query iterating
if (dm.Where != null && dm.Where.Count > 0)
{
var optr = dm.Where[0].predicates[0].Operator;
// converts based on your needs
var optrSymbol = "";
switch (optr)
{
case "equal" :
optrSymbol = "=";
break;
case "lessthan":
optrSymbol = "<";
break;
case "greaterthan":
optrSymbol = ">";
break;
. . .
default:
break;
}
var sqlString = dm.Table + '.' + dm.Where[0].predicates[0].Field + optrSymbol + dm.Where[0].predicates[0].value;
}
// execute your data operation
return Json(new { result = Data, count = Data.Count() }); // while using UrlAdaptor we need to return result and count object into grid
|
|
@Component({
selector: 'app-container',
template:
`
<button ejs-button id='load'cssClass="e-primary" (click)='sqlquery()'> Query </button>
<ejs-grid #grid [dataSource]='data' [filterSettings]='filterOptions' allowFiltering='true' height='272px' >
<e-columns>
<e-column field='OrderID' headerText='Order ID' width='120' textAlign="Right"></e-column>
<e-column field='EmployeeID' headerText='Employee ID' width='150'></e-column> </e-columns>
</ejs-grid>`,
styleUrls: ['index.css'],
})
export class AppComponent implements OnInit {
public data: Object[];
public customColumns: Object[];
public toolbarOptions: ToolbarItems[];
@ViewChild('grid')
public grid: GridComponent;
ngOnInit(): void {
this.data = data;
this.filterOptions = {
columns: [{ field: 'EmployeeID', matchCase: false, operator: 'equal', predicate: 'and', value: '1' },
]
};
}
sqlquery() { // you can your service link here with the generated string
var filterColumns = this.grid.filterSettings.columns;
for (let i = 0; i < filterColumns.length; i++) {
var optr = filterColumns[i].operator;
var optrSymbol = "";
var table = 'tblInvoice';
switch (optr) {
case "equal":
optrSymbol = "=";
break;
. . . .
}
var sqlString = table + '.' + filterColumns[i].field + optrSymbol + filterColumns[i].value;
}
}
}
|