Thread ID: |
Created: |
Updated: |
Platform: |
Replies: |
150608 | Jan 13,2020 01:07 PM UTC | Jan 27,2020 12:22 PM UTC | Vue | 5 |
![]() |
Tags: Data Grid |
public IActionResult UrlDatasource(DataManagerRequest dm)
{
IEnumerable DataSource = order;
DataOperations operation = new DataOperations();
. . .
List<string> str = new List<string>();
if (dm.Aggregates != null)
{
for (var i = 0; i < dm.Aggregates.Count; i++)
str.Add(dm.Aggregates[i].Field);
}
IEnumerable aggregate = operation.PerformSelect(DataSource, str);
int count = DataSource.Cast<Orders>().Count();
if (dm.Skip != 0)
{
DataSource = operation.PerformSkip(DataSource, dm.Skip); //Paging
}
if (dm.Take != 0)
{
DataSource = operation.PerformTake(DataSource, dm.Take);
}
return dm.RequiresCounts ? Json(new { result = DataSource, count = count, aggregate = aggregate }) : Json(DataSource);
} |
public IActionResult UrlDatasource(DataManagerRequest dm)
{
IEnumerable DataSource = order;
DataOperations operation = new DataOperations();
. . .
List<string> str = new List<string>();
if (dm.Aggregates != null)
{
for (var i = 0; i < dm.Aggregates.Count; i++)
str.Add(dm.Aggregates[i].Field);
}
IEnumerable aggregate = operation.PerformSelect(DataSource, str);
int count = DataSource.Cast<Orders>().Count();
if (dm.Skip != 0)
{
DataSource = operation.PerformSkip(DataSource, dm.Skip); //Paging
}
if (dm.Take != 0)
{
DataSource = operation.PerformTake(DataSource, dm.Take);
}
return dm.RequiresCounts ? Json(new { result = DataSource, count = count, aggregate = aggregate }) : Json(DataSource);
} |
[Vue]
<template>
<div class="col-lg-12 control-section">
<div>
<ejs-grid :dataSource="data" ref="grid" :load="load" :allowPaging="true">
<e-columns>
. . .
<e-column type="Custom" field="Freight" format="C2" :customAggregate="customAggregateFn" :footerTemplate="sumTemplate"></e-column>
</e-columns>
</e-aggregate>
</e-aggregates>
</ejs-grid>
</div>
</div>
</template>
<script>
import Vue from "vue";
import {
GridPlugin,
Sort,
Group,
Page,
Toolbar,
Aggregate
} from "@syncfusion/ej2-vue-grids";
import { DataManager, WebApiAdaptor,DataUtil } from "@syncfusion/ej2-data";
Vue.use(GridPlugin);
class extendedApiAdaptor extends WebApiAdaptor {
processResponse(
data, ds, query, xhr, request, changes) {
var original = super.processResponse.apply(this, arguments);
var aggregateData = data.Aggregate;
return DataUtil.isNull(original.count) ? original.result : { result: original.result, count: original.count, aggregates: aggregateData };
}
}
export default Vue.extend({
data() {
return {
data: new DataManager({
url: "api/Orders",
adaptor: new extendedApiAdaptor(),
crossDomain: true
}),
sumTemplate: function() {
return {
template: Vue.component("sumTemplate", {
template: `<span>Custom: {{data.Custom}}</span>`,
data: function() {
return { data: { data: {} } };
}
})
};
}
};
},
methods: {
load : function (e) {
var aggregatesField = ['Freight']
this.$refs.grid.ej2Instances.dataSource.dataSource.headers = [];
// add the required aggregates value to the header
this.$refs.grid.ej2Instances.dataSource.dataSource.headers.push({ aggregates: JSON.stringify(aggregatesField) });
},
customAggregateFn : function (data) {
console.log(data.aggregates);
// here you will get all the data for the aggregate
field and calculate your own aggregation
return calculated value
}
},
provide: {
grid: [Sort, Group, Aggregate, Page, Toolbar]
}
});
</script>
<style>
</style>
|
[Controller side]
public class OrderController : ApiController
{
// GET: api/Order
public object Get()
{
var queryString = System.Web.HttpContext.Current.Request.QueryString;
// get the values passed through request header
string agg = Request.Headers.GetValues("aggregates").ToList()[0];
DataOperations ds = new DataOperations();
object aggregate = null;
var data = OrdersDetails.GetAllRecords();
if (agg != null)
{
List<string> aggregates = (List<string>)JsonConvert.DeserializeObject(agg, typeof(List<string>));
aggregate = ds.PerformSelect(data, aggregates);
}
. . .
}
return new
{
//return the Aggregates along with result and count
Items = data.Skip(skip).Take(take),
Count = data.Count(),
Aggregate = aggregate
};
} |
This post will be permanently deleted. Are you sure you want to continue?
Sorry, An error occured while processing your request. Please try again later.
This page will automatically be redirected to the sign-in page in 10 seconds.