public DatatableRecords GetPagedRecords(DatatableFilters filters) { // Let's create the actual data to go into the table List <string[]> dtData = new List <string[]>(); for (int i = 0; i < 15; i++) { dtData.Add(new string[] { string.Format("first column paged row {0}", i + 1), string.Format("second column paged row {0}", i + 1) }); } DatatableRecords dtRecords = new DatatableRecords { sEcho = filters.sEcho, iTotalRecords = dtData.Count(), // Total records in table iTotalDisplayRecords = dtData.Count(), // Total records to be displayed in the table aaData = dtData .Skip(filters.iDisplayStart) // The data to be displayed .Take(filters.iDisplayLength) .ToArray() }; return(dtRecords); }
// // GET: /JQueryUI/Core/GetPostbackData public virtual JsonResult GetPostbackData(DatatableFilters filters, PostbackSetupViewModel postbacks) { IEnumerable <string[]> dtData = new string[][] { new string[] { "first column row 1", "second column row 1" }, new string[] { "first column row 2", "second column row 2" }, new string[] { "first column row 3", "second column row 3" }, new string[] { "first column row 4", "second column row 4" } }; if (!string.IsNullOrEmpty(postbacks.FirstColumn)) { dtData = dtData.Where(f => f[0].ContainsIgnoreCase(postbacks.FirstColumn)); } if (!string.IsNullOrEmpty(postbacks.SecondColumn)) { dtData = dtData.Where(f => f[1].ContainsIgnoreCase(postbacks.SecondColumn)); } DatatableRecords dtRecords = new DatatableRecords { sEcho = filters.sEcho, iTotalRecords = dtData.Count(), iTotalDisplayRecords = dtData.Count(), aaData = dtData.ToArray() }; return(Json(dtRecords, JsonRequestBehavior.AllowGet)); }
public void From_Returns_Correct_Records() { // Arrange DatatableTestClass[] records = DatatableTestClass.CreateData(); // Act DatatableRecords result = DatatableRecords.From(records); // Assert Assert.AreEqual(5, result.aaData.Length); }
public void Ctor_Test() { // Act m_records = new DatatableRecords(); // Assert Assert.AreEqual("1", m_records.sEcho); Assert.AreEqual(0, m_records.iTotalRecords); Assert.AreEqual(0, m_records.iTotalDisplayRecords); Assert.IsNotNull(m_records.aaData); Assert.AreEqual(0, m_records.aaData.Count()); }
public void Initialize() { m_records = new DatatableRecords(); m_records.aaData = new List <string[]> { new[] { "<a href='/displayplan/4'>4</a>", "mihir", "02-Jan-13", "€15.00" }, new[] { "<a href='/displayplan/24'>3</a>", "sneha", "2013-Mar-12", "£12.00" }, new[] { "<a href='/displayplan/11'>1</a>", "mohan", "20 Mar 13", "$151.00" }, new[] { "<a href='/displayplan/16'>2</a>", "swati", "29May13", "$201.00" } }.ToArray(); m_records.iTotalDisplayRecords = m_records.aaData.Count(); m_records.iTotalRecords = m_records.aaData.Count(); }
public DatatableRecords GetSortedRecords(DatatableFilters filters) { // Let's create the actual data to go into the table IList <string[]> dtData = DatatableGenerator.GetDataWithSpecialFormat(); DatatableRecords dtRecords = new DatatableRecords { sEcho = filters.sEcho, iTotalRecords = dtData.Count(), // Total records in table iTotalDisplayRecords = dtData.Count(), // Total records to be displayed in the table aaData = dtData .Sort(filters.iSortCol_0, filters.SortDirection) // The data to be displayed .ToArray() }; return(dtRecords); }
public virtual ActionResult Datatables(DatatablesViewModel viewModel) { // create the basic table again IEnumerable <AOColumn> dtAOColumns = new List <AOColumn> { new AOColumn { sTitle = "First Column", sWidth = "25%" }, new AOColumn { sTitle = "Second Column" } }; DatatableSettings dtSettings = new DatatableSettings(5, dtAOColumns, new AASort(0, ESort.Ascending), null, "basic records", "150px"); dtSettings.bJQueryUI = true; IEnumerable <string[]> dtData = new string[][] { new string[] { "first column row 1", "second column row 1" }, new string[] { "first column row 2", "second column row 2" }, new string[] { "first column row 3", "second column row 3" }, new string[] { "first column row 4", "second column row 4" } }; DatatableRecords dtRecords = new DatatableRecords { iTotalRecords = dtData.Count(), // Total records in table iTotalDisplayRecords = dtData.Count(), // Total records to be displayed in the table aaData = dtData.ToArray() // The data to be displayed }; viewModel.Table = new Datatable("basic-table", dtSettings, dtRecords); // create the postbacks enabled table IEnumerable <PostbackItem> dtPostbacks = PostbackItem.FromObject(viewModel.PostbackFormFields); dtSettings = new DatatableSettings(5, dtAOColumns, new AASort(0, ESort.Ascending), MVC.Bootstrap.Core.ActionNames.GetPostbackData, "searched/filtered records", "150px"); dtSettings.bJQueryUI = true; viewModel.PostbackEnabledTable = new Datatable("postbacks-table", dtSettings, null, dtPostbacks); // update the display mode viewModel.DisplayMode = 6; return(View(MVC.JQueryUI.Core.Views.Datatables, viewModel)); }
// // GET: /Bootstrap/Core/GetAjaxData public virtual JsonResult GetAjaxData(DatatableFilters filters) { // Let's create the actual data to go into the table string[][] dtData = new string[][] { new string[] { "first column ajax row 1", "second column ajax row 1" }, new string[] { "first column ajax row 2", "second column ajax row 2" } }; DatatableRecords dtRecords = new DatatableRecords { sEcho = filters.sEcho, iTotalRecords = dtData.Length, // Total records in table iTotalDisplayRecords = dtData.Length, // Total records to be displayed in the table aaData = dtData // The data to be displayed }; return(Json(dtRecords, JsonRequestBehavior.AllowGet)); }
// // GET: /Bootstrap/Core/Datatables public virtual ActionResult Datatables(int?mode) { if (!mode.HasValue) { return(RedirectToAction(Actions.Datatables(0))); } DatatablesViewModel model = new DatatablesViewModel(); string tableId = string.Empty; string tableHeight = null; IEnumerable <AOColumn> dtAOColumns = new List <AOColumn> { new AOColumn { sTitle = "First Column", sWidth = "25%" }, new AOColumn { sTitle = "Second Column" } }; DatatableSettings dtSettings = null; DatatableRecords dtRecords = null; bool enableStatusColumn = false; switch (mode) { case 1: tableId = "ajax-table"; dtSettings = new DatatableSettings(5, dtAOColumns, new AASort(0, ESort.Ascending), MVC.Bootstrap.Core.ActionNames.GetAjaxData, "ajax records", tableHeight); break; case 2: tableId = "paged-table"; dtSettings = new DatatableSettings(5, dtAOColumns, new AASort(0, ESort.Ascending), MVC.Bootstrap.Core.ActionNames.GetPagedData, "paged records", tableHeight); dtRecords = GetPagedRecords(new DatatableFilters { iDisplayStart = 0, iDisplayLength = 5 }); break; case 3: tableId = "paged-and-sorted-table"; dtAOColumns = new List <AOColumn> { new AOColumn { sTitle = "HTML field column", bSortable = true }, new AOColumn { sTitle = "String Column", bSortable = true }, new AOColumn { sTitle = "DateTime Column", bSortable = true }, new AOColumn { sTitle = "Numeric Column", bSortable = true }, new AOColumn { sTitle = "Currency Column", bSortable = true } }; dtSettings = new DatatableSettings(5, dtAOColumns, new AASort(0, ESort.Ascending), MVC.Bootstrap.Core.ActionNames.GetSortedData, "sorted records", tableHeight); dtRecords = GetSortedRecords(new DatatableFilters { iDisplayStart = 0, iDisplayLength = 5 }); break; case 4: tableId = "status-table"; dtSettings = new DatatableSettings(5, dtAOColumns, new AASort(0, ESort.Ascending), null, "status records", tableHeight); IEnumerable <string[]> statusData = DatatableGenerator.GetDefaultDataWithStatusColumn(); enableStatusColumn = true; dtRecords = new DatatableRecords { iTotalRecords = statusData.Count(), iTotalDisplayRecords = statusData.Count(), aaData = statusData.ToArray() }; break; case 0: case 5: default: tableId = "basic-table"; dtSettings = new DatatableSettings(5, dtAOColumns, new AASort(0, ESort.Ascending), null, "basic records", tableHeight); IEnumerable <string[]> dtData = DatatableGenerator.GetDefaultData(); dtRecords = new DatatableRecords { iTotalRecords = dtData.Count(), // Total records in table iTotalDisplayRecords = dtData.Count(), // Total records to be displayed in the table aaData = dtData.ToArray() // The data to be displayed }; break; } // Let's create the datatable object with an HTML ID, our settings, columns and records model.DisplayMode = mode.Value; model.Table = new Datatable(tableId, dtSettings, dtRecords, null, enableStatusColumn); return(View(model)); }
// // GET: /Bootstrap/Core/GetSortedData public virtual JsonResult GetSortedData(DatatableFilters filters) { DatatableRecords dtRecords = GetSortedRecords(filters); return(Json(dtRecords, JsonRequestBehavior.AllowGet)); }