public void RenderPageSize(PagingControlConfiguration pageConfig, int currentPageSize, string tableId, ControllerContext context) { if (pageConfig.PageSizes == null) { return; } var writer = WriterHelper.GetWriter(context); var name = StaticReflection.StaticReflection.GetMember((TableRequestModel m) => m.PageSize).Name; using (new ComplexContentTag("select", new Dictionary <string, object>() { { "data-target", tableId }, { "class", pageConfig.TableDefinition.FilterExpression + " mvc-table-page-size" }, { "name", name } }, writer)) { foreach (var pageSize in pageConfig.PageSizes) { if (currentPageSize == pageSize) { using (new ComplexContentTag("option", new { value = pageSize, selected = "selected" }, writer)) { writer.Write(pageSize); } } else { using (new ComplexContentTag("option", new { value = pageSize }, writer)) { writer.Write(pageSize); } } } } }
public void RenderPagination(PagingControlConfiguration pageConfig, string tableId, ControllerContext context) { var writer = WriterHelper.GetWriter(context); using ( new ComplexContentTag("div", new Dictionary <String, object> { { "class", pageConfig.ContainerCssClass + " mvctable-paginator" }, { "data-target", tableId } }, writer)) { object movePreviousClass = _paginator.Current.PageNumber == _paginator.First.PageNumber ? new { @class = pageConfig.DisabledCssClass } : null; using (new ComplexContentTag("ul", writer)) { using (new ComplexContentTag("li", movePreviousClass, writer)) { using ( new ComplexContentTag("a", new RouteValueDictionary(new { href = _paginator.First.Url }) .WithClass(pageConfig.TableDefinition.FilterExpression) .WithAttribute("data-target", tableId), writer)) { writer.Write(pageConfig.FirstPageText); } } using (new ComplexContentTag("li", movePreviousClass, writer)) { using ( new ComplexContentTag("a", new RouteValueDictionary(new { href = _paginator.Previous.Url }) .WithAttribute("data-target", tableId) .WithClass(pageConfig.TableDefinition.FilterExpression), writer)) { writer.Write(pageConfig.PreviousPageText); } } foreach (var page in _paginator.Pages) { object classObj = page.IsCurrent ? new { @class = pageConfig.ActiveCssClass } : null; using (new ComplexContentTag("li", classObj, writer)) { using ( new ComplexContentTag("a", new RouteValueDictionary(new { href = page.Url }) .WithAttribute("data-target", tableId) .WithClass(pageConfig.TableDefinition.FilterExpression), writer)) { writer.Write(page.PageNumber.ToString(Thread.CurrentThread.CurrentUICulture)); } } } object moveNextClass = _paginator.Current.PageNumber == _paginator.Last.PageNumber ? new { @class = pageConfig.DisabledCssClass } : null; using (new ComplexContentTag("li", moveNextClass, writer)) { using ( new ComplexContentTag("a", new RouteValueDictionary(new { href = _paginator.Next.Url }) .WithAttribute("data-target", tableId) .WithClass(pageConfig.TableDefinition.FilterExpression), writer)) { writer.Write(pageConfig.NextPageText); } } using (new ComplexContentTag("li", moveNextClass, writer)) { using ( new ComplexContentTag("a", new RouteValueDictionary(new { href = _paginator.Last.Url }) .WithAttribute("data-target", tableId) .WithClass(pageConfig.TableDefinition.FilterExpression), writer)) { writer.Write(pageConfig.LastPageText); } } } } }
public void Render(IEnumerable <TModel> rows, TableRequestModel model, ControllerContext context) { var writer = WriterHelper.GetWriter(context); var myId = _tableDefinition.Id; using ( new ComplexContentTag("div", new Dictionary <string, object> { { "class", HtmlConstants.MvctableContainer } }, writer)) { using (new ComplexContentTag("table", new Dictionary <string, object> { { "class", "mvctable " + _tableDefinition.CssClass }, { "data-source", _urlManager.SourceUrl }, { "data-table-id", myId }, { "data-filter", _tableDefinition.FilterExpression } }, writer)) { using (new ComplexContentTag("thead", writer)) { using (new ComplexContentTag("tr", writer)) { foreach (var col in _tableDefinition.Columns) { var attributes = col.HeaderAttributes.Clone(); if (col.IsSortable) { var sortAsc = model.SortAscending; var isSorted = model.SortColumn == col.SortExpression; var classMap = new[] { new { Apply = true, @class = "sortable" }, new { Apply = isSorted, @class = sortAsc ? "sorted-asc" : "sorted-desc" } }; attributes["class"] = attributes.ContainsKey("class") ? attributes["class"] : ""; foreach (var cm in classMap.Where(cm => cm.Apply)) { attributes["class"] += (" " + cm.@class); } } if (col.IsHidden) { attributes.WithStyle("display", "none"); } using (new ComplexContentTag("th", attributes, writer)) { if (col.IsSortable) { var sortUrl = _urlManager.GetSortUrl(col.SortExpression); using ( new ComplexContentTag("a", new RouteValueDictionary(new { href = sortUrl }) .WithClass(_tableDefinition.FilterExpression), writer)) { writer.Write(col.GetHeaderValue(context, writer)); } } else { writer.Write(col.GetHeaderValue(context, writer)); } } } } } using (new ComplexContentTag("tbody", writer)) { var aRows = rows.ToArray(); for (var i = 0; i < aRows.Length; i++) { using (new ComplexContentTag("tr", writer)) { foreach (var col in _tableDefinition.Columns) { if (col.IsHidden) { col.CellAttributes.WithStyle("display", "none"); } using (new ComplexContentTag("td", col.CellAttributes, writer)) { writer.Write(col.GetCellValue(aRows, i, context, writer)); } } } } } using (new ComplexContentTag("tfoot", writer)) { using (new ComplexContentTag("tr", writer)) { foreach (var col in _tableDefinition.Columns) { if (col.IsHidden) { col.FooterAttributes.WithStyle("display", "none"); } using (new ComplexContentTag("td", col.FooterAttributes, writer)) { writer.Write(col.GetFooterValue(rows, context, writer)); } } } } } } writer.Flush(); }