Skip to content

Instantly share code, notes, and snippets.

@hanssens
Created August 12, 2015 12:03
Show Gist options
  • Save hanssens/53a72ce1cf0feed28be6 to your computer and use it in GitHub Desktop.
Save hanssens/53a72ce1cf0feed28be6 to your computer and use it in GitHub Desktop.
Kendo server-side pageable grid
public class DataController : Controller
{
public JsonResult Products(int pageSize = 25, int skip = 0)
{
var products = ProductFactory.Create();
var total = products.Count();
var data = products.Skip(skip).Take(pageSize).ToList();
return Json(new { total = total, data = data }, JsonRequestBehavior.AllowGet);
}
}
<section id="example-serverside-grid">
<div class="row">
<div class="col-md-12">
<div data-role="grid"
data-columns="[
{ 'field': 'Id', 'width': 100 },
{ 'field': 'Name' },
{ 'field': 'Price', 'width': 100 },
]"
data-bind="source: products"
data-pageable="true"
style="height: 450px"></div>
</div>
</div>
</section>
@section scripts {
<link rel="stylesheet" href="//kendo.cdn.telerik.com/2015.2.805/styles/kendo.common-material.min.css"/>
<link rel="stylesheet" href="//kendo.cdn.telerik.com/2015.2.805/styles/kendo.material.min.css"/>
<script src="//kendo.cdn.telerik.com/2015.2.805/js/kendo.all.min.js"></script>
<script>
$(function() {
var dataSource = new kendo.data.DataSource({
serverPaging: true,
pageSize: 10,
schema: {
// map to the 'data' and 'total' properties, returned by the api
data: "data",
total: "total"
},
transport: {
read: {
// define the api endpoint for 'read' operations
url: "/data/products",
dataType: "json"
}
}
});
var viewmodel = kendo.observable({
products: dataSource
});
kendo.bind($("#example-serverside-grid"), viewmodel);
});
</script>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment