<div id="Grid"></div>
<script type="text/javascript">
$(function () {
$("#Grid").ejGrid({
dataSource: ej.DataManager({
url: "/api/Values",
adaptor: new ej.WebApiAdaptor()
}),
allowScrolling: true,
scrollSettings: { height: 300, allowVirtualScrolling: true, virtualScrollMode: ej.Grid.VirtualScrollMode.Continuous },
. . . .
});
});
</script>
public IHttpActionResult Get(ODataQueryOptions<Order> opts)
{
var obj = new NorthWndDataContext().Orders.ToList();
var result = new PageResult<Order>(opts.ApplyTo(obj.AsQueryable()) as IEnumerable<Order>, null, obj.Count);
return Ok(result);
}
|
[Razor]
@(Html.EJ().Grid<Sample.Models.OrdersView>("Grid")
.Datasource(d => d.URL("/Home/partialGrid").Adaptor("UrlAdaptor"))
.AllowScrolling()
.ScrollSettings(cl => {
cl.AllowVirtualScrolling()
.Height(300)
.VirtualScrollMode(VirtualScrollMode.Continuous);
})
)
[Controller]
public ActionResult partialGrid(DataManager dm)
{
var DataSource = OrderRepository.GetAllRecords().ToList();
DataResult result = new DataResult();
result.result = DataSource.Skip(dm.Skip).Take(dm.Take).ToList();
result.count = DataSource.Count();
return Json(result, JsonRequestBehavior.AllowGet);
} |
<div id="Grid"></div>
<script src="~/Scripts/jsondata.min.js"></script>
<script type="text/javascript">
$(function () {
var customAdaptor = new ej.UrlAdaptor().extend({
processResponse: function (data, ds, query, xhr, request, changes) {
var obj = $("#Grid").ejGrid("instance");
var pageSize = obj.model.pageSettings.pageSize;
var currentPage = obj.model.pageSettings.currentPage;
result = getData(pageSize, currentPage);
return result;
}
});
function getData(size, cPage) {
var skip = 0, take = 0;
if (cPage > 1)
skip = size * cPage;
take = size;
var count = window.gridData.length;
if (count == skip)
skip = skip - size;
var result = ej.DataManager(window.gridData).executeLocal(new ej.Query().skip(skip).take(take));
return { result: result, count: count };
}
$("#Grid").ejGrid({
dataSource: ej.DataManager({
json: [],
adaptor: new customAdaptor()
}),
allowScrolling: true,
scrollSettings: {
height: 300,
allowVirtualScrolling: true,
virtualScrollMode: ej.Grid.VirtualScrollMode.Continuous
},
. . . . . .
});
});
</script>
|