1-View
@(Html.Telerik().Grid<Model Name>() .Name("Grid") .Columns(columns => { columns.Bound(Field Name).Width(40).Title("Title"); //Bound All columns here
}) .DataBinding(dataBinding => dataBinding.Ajax().Select("Action Name", "Controller"))//put number of row you want to display itin every page for example 10.Pageable(set => set.PageSize(10)))
2-Controller
[GridAction(EnableCustomBinding = true)] public ActionResult GetStudyList(int page) { int resultCount = 0; int totalRowsCount = 0; int pageIndex = Convert.ToInt32(page) - 1; string sidx = "TimeStamp"; string sord = "desc"; int rows = 10;//as page size in View Dictionary<StudyViewColumn, string> parameters = new Dictionary<StudyViewColumn, string>(); parameters.Add(Parmeter); var data = Find(out resultCount, out totalRowsCount, parameters, sidx, sord, (pageIndex * rows), rows).AsQueryable(); var list = from d in data select new model Name() { //set model data }; return View(new GridModel<Model Name> { Data = list, Total = totalRowsCount //total rows });}
3-Find Function
public TList<Study> Find(Dictionary<StudyColumn, string> parameters, string orderBy, string direction, int? start, int? pageLength, out int ResultCount, out int totalRowsCount) { TList<Study> list; StudyParameterBuilder filter = new StudyParameterBuilder(); foreach (KeyValuePair<StudyColumn, string> dictEntry in parameters) { if (!string.IsNullOrEmpty(dictEntry.Value)) { switch (dictEntry.Key) { case StudyColumn.StudyGuid: case StudyColumn.PatientGuid: filter.AppendEquals(dictEntry.Key, dictEntry.Value); break; //and so on...
} } } if (!string.IsNullOrEmpty(orderBy)) { if (!string.IsNullOrEmpty(direction)) { orderBy += " " + direction; } if (start != null && pageLength != null) { list = Find(filter, orderBy, (int)start, (int)pageLength, out totalRowsCount); } else { list = Find(filter, orderBy); totalRowsCount = list.Count; } } else { list = Find(filter); totalRowsCount = list.Count; } if (list != null) { ResultCount = list.Count; } else { ResultCount = 0; } return list;
}