@{
ViewData["Title"] = "Grid";
}
<div id="Grid">
</div>
<script type="text/javascript">
$(function () {
var data = new ej.data.DataManager({
url: '/api/Orders',
adaptor: new ej.data.WebApiAdaptor(),
crossDomain: true
});
var grid = new ej.grids.Grid({
dataSource: data,
allowPaging: true,
allowFiltering: true,
toolbar: ['Search'],
actionBegin: actionBegin,
pageSettings: { pageSize: 15 },
columns: [
{ field: 'OrderID', headerText: 'Order ID', textAlign: 'Right', width: 120, isPrimaryKey: true },
{ field: 'EmployeeID', width: 140, headerText: 'Employee ID' },
{ field: 'ShipCountry', headerText: 'Ship Country', width: 140 }
]
});
grid.appendTo('#Grid');
});
</script>
<script>
function actionBegin(args) {
if (args.requestType === "filtering") {
this.query = this.query.addParams("requestType", args.requestType)
}
else if (args.requestType === "searching") {
this.query = this.query.addParams("requestType", args.requestType)
}
}
</script>
|
...
<script type="text/javascript">
$(function () {
...
var grid = new ej.grids.Grid({
dataSource: data,
allowPaging: true,
allowFiltering: true,
toolbar: ['Search'],
actionBegin: actionBegin,
pageSettings: { pageSize: 15 },
columns: [
...
]
});
grid.appendTo('#Grid');
});
</script>
<script>
function actionBegin(args) {
if (args.requestType === "filtering") {
if (this.query.params.length > 0) { //checked whether the params present or not
this.query.params = []; //emptied params
this.query = this.query.addParams("requestType", args.requestType);
} else {
this.query = this.query.addParams("requestType", args.requestType);
}
}
else if (args.requestType === "searching") {
if (this.query.params.length > 0) { //checked whether the params present or not
this.query.params = []; //emptied params
this.query = this.query.addParams("requestType", args.requestType);
} else {
this.query = this.query.addParams("requestType", args.requestType);
}
}
}
</script> |