Grid - Server binding


About this example


This demo shows DJME Grid using Server requests (HTTP GET) for paging, sorting, filtering and grouping.In this demo using the customers data of Northwind database that generate by EF.

Before we binding the Customer data model to Grid we need to write a data source Action which getting the customer data from database. and then
1.Create your data source action
In DJME2 beta2 there offers a new data class to help you write server data source action inline.

        [Pagable] //  1.Add PagableAttribute  on your Action
        public ActionResult Contacts(QueryParams _params) 
        // 2.Add QueryParams param as Action parameter
        {
            var db = new NorthWindEntities();
            //3.Using ModelBinder.BindForGrid method to generate pageable,sotable,groupable data.
            return View(ModelBinder.BindForGrid(c => c.CustomerID, db.Customers, _params));
        }
Put the Grid extension on your view

<%
   Ajax.Dna().Grid(Model)
         .Columns(cols=>{
            //Binding the columns which need to display
            cols.Bound(m=>m.FieldNameHere);
            ...
         })
         .Pagable()
         .Sortable()
         .Render();
%>

Notes: If you need the Grid allow Grouping you need to specified your View Model Type as IEnumerable and inject the Model type in Grid method.

<%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
<%
   Ajax.Dna().Grid(Model)
   ...
                .Groupable()
                .Render();
%>