@@ -20,6 +20,7 @@ public abstract class GriddlySettings
20
20
public static HtmlString BoolFalseHtml = null ;
21
21
public static int ? DefaultPageSize = null ;
22
22
public static bool DefaultShowFilterInitially = true ;
23
+ public static bool DefaultShowRowSelectCount = true ;
23
24
24
25
public static Func < GriddlyButton , object > IconTemplate = null ;
25
26
public static Func < GriddlyResultPage , object > DefaultFooterTemplate = null ;
@@ -30,23 +31,29 @@ public abstract class GriddlySettings
30
31
public GriddlySettings ( )
31
32
{
32
33
IdProperty = "Id" ;
34
+ HasInlineFilter = true ;
35
+
33
36
Columns = new List < GriddlyColumn > ( ) ;
34
37
Filters = new List < GriddlyFilter > ( ) ;
35
38
Buttons = new List < GriddlyButton > ( ) ;
39
+ RowIds = new Dictionary < string , Func < object , object > > ( ) ;
40
+
36
41
ClassName = DefaultClassName ;
37
42
TableClassName = DefaultTableClassName ;
38
43
FooterTemplate = DefaultFooterTemplate ;
39
44
PageSize = DefaultPageSize ;
40
45
ShowFilterInitially = DefaultShowFilterInitially ;
41
- HasInlineFilter = true ;
46
+ ShowRowSelectCount = DefaultShowRowSelectCount ;
42
47
}
43
48
49
+ public string [ ] DefaultRowIds { get ; set ; }
44
50
public string IdProperty { get ; set ; }
45
51
public string Title { get ; set ; }
46
52
public string ClassName { get ; set ; }
47
53
public string TableClassName { get ; set ; }
48
54
public string OnClientRefresh { get ; set ; }
49
55
public bool ShowFilterInitially { get ; set ; }
56
+ public bool ShowRowSelectCount { get ; set ; }
50
57
51
58
public int ? PageSize { get ; set ; }
52
59
public int ? MaxPageSize { get ; set ; }
@@ -68,6 +75,8 @@ public GriddlySettings()
68
75
69
76
public bool HasInlineFilter { get ; set ; }
70
77
78
+ public Dictionary < string , Func < object , object > > RowIds { get ; protected set ; }
79
+
71
80
public virtual bool HasRowClickUrl
72
81
{
73
82
get { return RowClickUrl != null ; }
@@ -88,6 +97,19 @@ public virtual object RenderRowClass(object o)
88
97
return RowClass ( o ) ;
89
98
}
90
99
100
+ public GriddlySettings RowId ( Expression < Func < object , object > > expression , string name = null )
101
+ {
102
+ if ( name == null )
103
+ {
104
+ var meta = ModelMetadata . FromLambdaExpression ( expression , new ViewDataDictionary < object > ( ) ) ;
105
+ name = ExpressionHelper . GetExpressionText ( expression ) ;
106
+ }
107
+
108
+ RowIds [ name ?? "id" ] = expression . Compile ( ) ;
109
+
110
+ return this ;
111
+ }
112
+
91
113
public GriddlySettings Add ( GriddlyColumn column , Func < GriddlyColumn , GriddlyFilter > filter = null )
92
114
{
93
115
if ( filter != null )
@@ -125,7 +147,7 @@ public GriddlySettings Add(GriddlyButton button)
125
147
});
126
148
}*/
127
149
128
- public GriddlySettings Button ( Func < object , object > argumentTemplate , string caption , string icon = null , GriddlyButtonAction action = GriddlyButtonAction . Navigate , bool ? enableOnSelection = null , string className = null , string target = null )
150
+ public GriddlySettings Button ( Func < object , object > argumentTemplate , string caption , string icon = null , GriddlyButtonAction action = GriddlyButtonAction . Navigate , bool ? enableOnSelection = null , string className = null , string target = null , string [ ] rowIds = null )
129
151
{
130
152
if ( enableOnSelection == null )
131
153
enableOnSelection = ( action == GriddlyButtonAction . Ajax || action == GriddlyButtonAction . AjaxBulk || action == GriddlyButtonAction . Post ) ;
@@ -137,13 +159,14 @@ public GriddlySettings Button(Func<object, object> argumentTemplate, string capt
137
159
Icon = icon ,
138
160
Action = action ,
139
161
EnableOnSelection = enableOnSelection . Value ,
140
- Target = target
162
+ Target = target ,
163
+ RowIds = rowIds
141
164
} ;
142
165
143
166
return Add ( button ) ;
144
167
}
145
168
146
- public GriddlySettings Button ( string argument , string caption , string icon = null , GriddlyButtonAction action = GriddlyButtonAction . Navigate , bool ? enableOnSelection = null , string className = null , string target = null )
169
+ public GriddlySettings Button ( string argument , string caption , string icon = null , GriddlyButtonAction action = GriddlyButtonAction . Navigate , bool ? enableOnSelection = null , string className = null , string target = null , string [ ] rowIds = null )
147
170
{
148
171
if ( enableOnSelection == null )
149
172
enableOnSelection = ( action == GriddlyButtonAction . Ajax || action == GriddlyButtonAction . AjaxBulk || action == GriddlyButtonAction . Post ) ;
@@ -155,7 +178,8 @@ public GriddlySettings Button(string argument, string caption, string icon = nul
155
178
Icon = icon ,
156
179
Action = action ,
157
180
EnableOnSelection = enableOnSelection . Value ,
158
- Target = target
181
+ Target = target ,
182
+ RowIds = rowIds
159
183
} ;
160
184
161
185
return Add ( button ) ;
@@ -169,11 +193,26 @@ public GriddlySettings ButtonSeparator()
169
193
} ) ;
170
194
}
171
195
172
- public GriddlySettings SelectColumn ( Func < object , object > id )
196
+ public GriddlySettings SelectColumn ( Expression < Func < object , object > > id , object summaryValue = null )
173
197
{
198
+ RowId ( id , "id" ) ;
199
+
174
200
return Add ( new GriddlySelectColumn ( )
175
201
{
176
- Id = id
202
+ SummaryValue = summaryValue
203
+ } ) ;
204
+ }
205
+
206
+ public GriddlySettings SelectColumn ( Dictionary < string , Func < object , object > > ids , object summaryValue = null )
207
+ {
208
+ foreach ( var x in ids )
209
+ {
210
+ RowIds [ x . Key ] = x . Value ;
211
+ }
212
+
213
+ return Add ( new GriddlySelectColumn ( )
214
+ {
215
+ SummaryValue = summaryValue
177
216
} ) ;
178
217
}
179
218
@@ -242,6 +281,19 @@ public class GriddlySettings<TRow> : GriddlySettings
242
281
base . RowClass = null ;
243
282
}
244
283
}
284
+
285
+ public GriddlySettings < TRow > RowId ( Expression < Func < TRow , object > > expression , string name = null )
286
+ {
287
+ if ( name == null )
288
+ {
289
+ var meta = ModelMetadata . FromLambdaExpression ( expression , new ViewDataDictionary < TRow > ( ) ) ;
290
+ name = ExpressionHelper . GetExpressionText ( expression ) ;
291
+ }
292
+
293
+ RowIds [ name ?? "id" ] = ( x ) => expression . Compile ( ) ( ( TRow ) x ) ;
294
+
295
+ return this ;
296
+ }
245
297
246
298
public GriddlySettings < TRow > Column < TProperty > ( Expression < Func < TRow , TProperty > > expression , string caption = null , string format = null , string expressionString = null , SortDirection ? defaultSort = null , string className = null , bool isExportOnly = false , string width = null , SummaryAggregateFunction ? summaryFunction = null , object summaryValue = null , Func < TRow , object > template = null , Func < GriddlyColumn , GriddlyFilter > filter = null )
247
299
{
@@ -330,26 +382,42 @@ public GriddlySettings<TRow> Column(string caption = null, string format = null,
330
382
// return this;
331
383
//}
332
384
333
- public GriddlySettings < TRow > SelectColumn ( Func < TRow , object > id , object summaryValue = null )
385
+ public GriddlySettings < TRow > SelectColumn ( Expression < Func < TRow , object > > id , object summaryValue = null )
334
386
{
387
+ RowId ( id , "id" ) ;
388
+
335
389
Add ( new GriddlySelectColumn ( )
336
390
{
337
- Id = ( x ) => id ( ( TRow ) x ) ,
338
- ClassName = "align-center" ,
339
391
SummaryValue = summaryValue
340
392
} ) ;
341
393
342
394
return this ;
343
395
}
344
396
345
- public GriddlySettings < TRow > Button < TModel > ( Func < TModel , object > argumentTemplate , string caption , string icon = null , GriddlyButtonAction action = GriddlyButtonAction . Navigate )
397
+ public GriddlySettings < TRow > SelectColumn ( Dictionary < string , Func < TRow , object > > ids , object summaryValue = null )
398
+ {
399
+ foreach ( var x in ids )
400
+ {
401
+ RowIds [ x . Key ] = ( z ) => x . Value ( ( TRow ) z ) ;
402
+ }
403
+
404
+ Add ( new GriddlySelectColumn ( )
405
+ {
406
+ SummaryValue = summaryValue
407
+ } ) ;
408
+
409
+ return this ;
410
+ }
411
+
412
+ public GriddlySettings < TRow > Button < TModel > ( Func < TModel , object > argumentTemplate , string caption , string icon = null , GriddlyButtonAction action = GriddlyButtonAction . Navigate , string [ ] rowIds = null )
346
413
{
347
414
Add ( new GriddlyButton ( )
348
415
{
349
416
ArgumentTemplate = ( x ) => argumentTemplate ( ( TModel ) x ) ,
350
417
Text = caption ,
351
418
Icon = icon ,
352
- Action = action
419
+ Action = action ,
420
+ RowIds = rowIds
353
421
} ) ;
354
422
355
423
return this ;
0 commit comments