-
Notifications
You must be signed in to change notification settings - Fork 134
/
SGrid.cs
132 lines (112 loc) · 5.24 KB
/
SGrid.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
using GridCore;
using GridCore.Columns;
using GridCore.Filtering;
using GridCore.Pagination;
using GridCore.Resources;
using GridCore.Searching;
using GridCore.Sorting;
using GridCore.Totals;
using GridMvc.Columns;
using GridMvc.DataAnnotations;
using GridShared;
using GridShared.Columns;
using GridShared.Pagination;
using GridShared.Utility;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Primitives;
using System.Collections.Generic;
using System.Linq;
namespace GridMvc
{
/// <summary>
/// Grid.Mvc base class
/// </summary>
public class SGrid<T> : SGridCore<T>
{
public SGrid()
{ }
public SGrid(IEnumerable<T> items, IQueryCollection query, bool renderOnlyRows,
string pagerViewName = GridPager.DefaultPagerViewName, IColumnBuilder<T> columnBuilder = null)
: this(items, GridExtensions.Convert(query), renderOnlyRows, pagerViewName, columnBuilder)
{
}
public SGrid(IEnumerable<T> items, QueryDictionary<string> query, bool renderOnlyRows,
string pagerViewName = GridPager.DefaultPagerViewName, IColumnBuilder<T> columnBuilder = null)
: this(items, query.ToStringValuesDictionary(), renderOnlyRows, pagerViewName, columnBuilder)
{
}
public SGrid(IEnumerable<T> items, QueryDictionary<StringValues> query, bool renderOnlyRows,
string pagerViewName = GridPager.DefaultPagerViewName, IColumnBuilder<T> columnBuilder = null)
: this(items, query, columnBuilder)
{
if (PagingType != PagingType.Virtualization)
{
((GridPager)_pager).TemplateName = pagerViewName;
}
RenderOptions.RenderRowsOnly = renderOnlyRows;
}
public SGrid(IEnumerable<T> items, IQueryCollection query, IColumnBuilder<T> columnBuilder = null)
: this(items, GridExtensions.Convert(query), columnBuilder)
{ }
public SGrid(IEnumerable<T> items, QueryDictionary<string> query, IColumnBuilder<T> columnBuilder = null)
: this(items, query.ToStringValuesDictionary(), columnBuilder)
{ }
public SGrid(IEnumerable<T> items, QueryDictionary<StringValues> query, IColumnBuilder<T> columnBuilder = null)
: this()
{
BeforeItems = items.AsQueryable();
#region init default properties
Query = query;
//set up sort settings:
_settings = new QueryStringGridSettingsProvider(Query);
Sanitizer = new Sanitizer();
EmptyGridText = Strings.DefaultGridEmptyText;
Language = Strings.Lang;
_currentSortItemsProcessor = new SortGridItemsProcessor<T>(this, _settings.SortSettings);
_currentFilterItemsProcessor = new FilterGridItemsProcessor<T>(this, _settings.FilterSettings);
_currentSearchItemsProcessor = new SearchGridItemsProcessor<T>(this, _settings.SearchSettings);
_currentTotalsItemsProcessor = new TotalsGridItemsProcessor<T>(this);
AddItemsPreProcessor(_currentFilterItemsProcessor);
AddItemsPreProcessor(_currentSearchItemsProcessor);
InsertItemsProcessor(0, _currentSortItemsProcessor);
SetTotalsProcessor(_currentTotalsItemsProcessor);
#endregion init default properties
_annotations = new GridAnnotationsProvider();
//Set up column collection:
if (columnBuilder == null)
_columnBuilder = new DefaultColumnBuilder<T>(this, _annotations);
else
_columnBuilder = columnBuilder;
_columnsCollection = new GridColumnCollection<T>(this, _columnBuilder, _settings.SortSettings);
RenderOptions = new GridRenderOptions();
ApplyGridSettings();
var urlParameters = CustomQueryStringBuilder.Convert(query);
int page = 0;
int startIndex = 0;
int virtualizedCount = 0;
bool noTotals = false;
string startIndexParameter = urlParameters[GridPager.DefaultStartIndexQueryParameter];
string virtualizedCountParameter = urlParameters[GridPager.DefaultVirtualizedCountQueryParameter];
string noTotalsParameter = urlParameters[GridPager.DefaultNoTotalsParameter];
if (!string.IsNullOrEmpty(startIndexParameter) && !string.IsNullOrWhiteSpace(virtualizedCountParameter))
{
PagingType = PagingType.Virtualization;
int.TryParse(startIndexParameter, out startIndex);
int.TryParse(virtualizedCountParameter, out virtualizedCount);
((GridPager)Pager).StartIndex = startIndex;
((GridPager)Pager).VirtualizedCount = virtualizedCount;
if (bool.TryParse(noTotalsParameter, out noTotals))
((GridPager)Pager).NoTotals = noTotals;
}
else
{
string pageParameter = urlParameters[((GridPager)Pager).ParameterName];
if (pageParameter != null)
int.TryParse(pageParameter, out page);
if (page == 0)
page++;
((GridPager)Pager).CurrentPage = page;
}
}
}
}