public BsGridPagerBuilder(BsPagerModel pager, BsPagerSettings settings, BsGridBaseRepositorySettings baseSettings) { this.renderer = new BsPagerBaseRenderer(this); this.pager = pager; this.settings = settings; this.baseSettings = baseSettings; }
public static BsGridPagerBuilder BsPager(this HtmlHelper html, BsPagerModel model) { var builder = new BsGridPagerBuilder(model, new BsPagerSettings(), null) { viewContext = html.ViewContext }; return(builder); }
private void SetResult <TValue>(BsGridModel <TRow> result, IQueryable <TEntity> basicQuery, BsGridBaseRepositorySettings settings, Expression <Func <TEntity, TValue> > uniqueIdSelector) { var totalRecords = basicQuery.Select(x => false).Count(); if (totalRecords > 0) { var pager = new BsPagerModel(totalRecords, this.settings.PageSize, this.settings.Page); IEnumerable <TRow> finalQuery = null; if (totalRecords > 1) { var orderedQuery = this.OrderQuery(basicQuery); if (settings.OrderableColumns.Any(c => c.Type == BsOrderType.Descending)) { orderedQuery = orderedQuery.ThenByDescending(uniqueIdSelector); } else { orderedQuery = orderedQuery.ThenBy(uniqueIdSelector); } var pagedQuery = orderedQuery.Skip(pager.PageSize * (pager.CurrentPage - 1)).Take(pager.PageSize); finalQuery = this.MapQuery(pagedQuery); } else { finalQuery = this.MapQuery(basicQuery); } // get items for current page result.Items = finalQuery.ToList(); //sets pager pager.CurrentPageRecords = result.Items.Count(); result.Pager = pager; } else { result.Items = new List <TRow>(); } }
private void SetNoOffsetResult <TValue>(BsGridModel <TRow> result, IQueryable <TEntity> basicQuery, BsGridBaseRepositorySettings settings, Expression <Func <TEntity, TValue> > uniqueIdSelector) { var pager = new BsPagerModel { PageSize = settings.PageSize }; IEnumerable <TRow> finalQuery = new List <TRow>(); pager.GoTo = settings.GoTo.Value; if (settings.GoTo.Value == BsDirectionType.Last) { this.SwitchOrderType(result); } var orderedPagerQuery = this.OrderAndPaginate(basicQuery, uniqueIdSelector); if (settings.GoTo.Value == BsDirectionType.Last) { this.SwitchOrderType(result); } var pagedQuery = this.OrderQuery(orderedPagerQuery.Take(pager.PageSize)); pagedQuery = this.OrderByUniqueId(pagedQuery, uniqueIdSelector); finalQuery = this.MapQuery(pagedQuery); result.Items = finalQuery.ToList(); result.Pager = pager; result.Pager.CurrentPageRecords = result.Items.Count(); result.Pager.TotalRecords = result.Pager.CurrentPageRecords; }
/// <summary> /// Creates GridModel based on Query, OrderQuery and MapQuery /// </summary> /// <param name="settings">Requested settings</param> /// <returns>Grid model</returns> public virtual BsGridModel <TRow> ToBsGridViewModel(BsGridBaseRepositorySettings settings) { this.settings = settings; var result = new BsGridModel <TRow>(); //creates basic query var basicQuery = this.Query(); //performs count var totalRecords = basicQuery.Select(x => false).Count(); //add column order result.BaseSettings.OrderColumns = settings.OrderColumns; //add orderable columns result.BaseSettings.OrderableColumns = settings.OrderableColumns; if (totalRecords > 0) { var pager = new BsPagerModel(totalRecords, this.settings.PageSize, this.settings.Page); IEnumerable <TRow> finalQuery = null; if (totalRecords > 1) { this.orderedQueryBuilder = new OrderedQueryBuilder <TRow>(this.settings.OrderableColumns); var orderedQuery = this.OrderQuery(basicQuery); var pagedQuery = orderedQuery.Skip(pager.PageSize * (pager.CurrentPage - 1)).Take(pager.PageSize); finalQuery = this.MapQuery(pagedQuery); } else { finalQuery = this.MapQuery(basicQuery); } // get items for current page result.Items = finalQuery.ToList(); //sets pager pager.CurrentPageRecords = result.Items.Count(); result.Pager = pager; if (settings.DetailsAll || settings.DetailsCount > 0) { for (var i = 0; i < pager.CurrentPageRecords; i++) { if (settings.HasDetails(i)) { var row = result.Items.ElementAt(i); this.FillDetails(row); } } } } else { result.Items = new List <TRow>(); } //sets base settings result.BaseSettings = this.settings.GetBase(); return(result); }