private IEnumerable <TableItem> GetData() { if (Items != null || ItemsQueryable != null) { if (Items != null) { ItemsQueryable = Items.AsQueryable(); } foreach (var item in Columns) { if (item.Filter != null) { ItemsQueryable = ItemsQueryable.Where(item.Filter.AddNullChecks()); } } // Global Search if (!string.IsNullOrEmpty(GlobalSearch) && Columns.Count > 0) { ItemsQueryable = ItemsQueryable.Where(GlobalSearchQuery(GlobalSearch)); } TotalCount = ItemsQueryable.Count(); var sortColumn = Columns.Find(x => x.SortColumn); if (sortColumn != null) { if (sortColumn.SortDescending) { ItemsQueryable = ItemsQueryable.OrderByDescending(sortColumn.Field); } else { ItemsQueryable = ItemsQueryable.OrderBy(sortColumn.Field); } } // if the current page is filtered out, we should go back to a page that exists if (PageNumber > TotalPages) { PageNumber = TotalPages - 1; } UpdaePageList(); // if PageSize is zero, we return all rows and no paging if (PageSize <= 0) { return(ItemsQueryable.ToList()); } else { return(ItemsQueryable.Skip(PageNumber * PageSize).Take(PageSize).ToList()); } } return(Items); }
private IEnumerable <TableItem> GetData() { if (Items != null || ItemsQueryable != null) { if (Items != null) { ItemsQueryable = Items.AsQueryable(); } foreach (var item in Columns) { if (item.Filter != null) { ItemsQueryable = ItemsQueryable.Where(item.Filter); } } TotalCount = ItemsQueryable.Count(); var sortColumn = Columns.Find(x => x.SortColumn); if (sortColumn != null) { if (sortColumn.SortDescending) { ItemsQueryable = sortColumn.DisableNaturalSort ? ItemsQueryable.OrderByDescending(sortColumn.Field) : ItemsQueryable.OrderByNaturalDescending(sortColumn.Field); } else { ItemsQueryable = sortColumn.DisableNaturalSort ? ItemsQueryable.OrderBy(sortColumn.Field) : ItemsQueryable.OrderByNatural(sortColumn.Field); } } // if PageSize is zero, we return all rows and no paging if (PageSize <= 0) { return(ItemsQueryable.ToList()); } else { return(ItemsQueryable.Skip(PageNumber * PageSize).Take(PageSize).ToList()); } } return(Items); }