7
7
using System . Web ;
8
8
using System . Web . Helpers ;
9
9
using System . Web . Mvc ;
10
+ using System . Web . Routing ;
10
11
11
12
namespace Griddly . Mvc
12
13
{
@@ -45,6 +46,8 @@ public GriddlySettings()
45
46
Filters = new List < GriddlyFilter > ( ) ;
46
47
Buttons = new List < GriddlyButton > ( ) ;
47
48
RowIds = new Dictionary < string , Func < object , object > > ( ) ;
49
+ HtmlAttributes = new RouteValueDictionary ( ) ;
50
+ TableHtmlAttributes = new RouteValueDictionary ( ) ;
48
51
49
52
ClassName = DefaultClassName ;
50
53
TableClassName = DefaultTableClassName ;
@@ -64,6 +67,8 @@ public GriddlySettings()
64
67
public FilterMode ? AllowedFilterModes { get ; set ; }
65
68
public FilterMode ? InitialFilterMode { get ; set ; }
66
69
public bool ShowRowSelectCount { get ; set ; }
70
+ public IDictionary < string , object > HtmlAttributes { get ; set ; }
71
+ public IDictionary < string , object > TableHtmlAttributes { get ; set ; }
67
72
68
73
public int ? PageSize { get ; set ; }
69
74
public int ? MaxPageSize { get ; set ; }
@@ -80,6 +85,7 @@ public GriddlySettings()
80
85
public Func < object , object > RowClickUrl { get ; set ; }
81
86
public string RowClickModal { get ; set ; }
82
87
public Func < object , object > RowClass { get ; set ; }
88
+ public Func < object , object > RowHtmlAttributes { get ; set ; }
83
89
84
90
public Func < GriddlyResultPage , object > FooterTemplate { get ; set ; }
85
91
public Func < GriddlyResultPage , object > HeaderTemplate { get ; set ; }
@@ -106,6 +112,29 @@ public virtual object RenderRowClass(object o)
106
112
return RowClass ( o ) ;
107
113
}
108
114
115
+ public virtual IDictionary < string , object > GenerateRowHtmlAttributes ( object o )
116
+ {
117
+ if ( RowHtmlAttributes != null )
118
+ {
119
+ object value = RowHtmlAttributes ( o ) ;
120
+
121
+ if ( value != null )
122
+ {
123
+ RouteValueDictionary attributes = new RouteValueDictionary ( ) ;
124
+
125
+ if ( ! ( value is IDictionary < string , object > ) )
126
+ value = HtmlHelper . AnonymousObjectToHtmlAttributes ( value ) ;
127
+
128
+ foreach ( KeyValuePair < string , object > entry in ( IDictionary < string , object > ) value )
129
+ attributes . Add ( entry . Key , entry . Value ) ;
130
+
131
+ return attributes ;
132
+ }
133
+ }
134
+
135
+ return null ;
136
+ }
137
+
109
138
public GriddlySettings RowId ( Expression < Func < object , object > > expression , string name = null )
110
139
{
111
140
if ( name == null )
@@ -339,6 +368,17 @@ public class GriddlySettings<TRow> : GriddlySettings
339
368
}
340
369
}
341
370
371
+ public new Func < TRow , object > RowHtmlAttributes
372
+ {
373
+ set
374
+ {
375
+ if ( value != null )
376
+ base . RowHtmlAttributes = ( x ) => value ( ( TRow ) x ) ;
377
+ else
378
+ base . RowHtmlAttributes = null ;
379
+ }
380
+ }
381
+
342
382
public GriddlySettings < TRow > RowId ( Expression < Func < TRow , object > > expression , string name = null )
343
383
{
344
384
if ( name == null )
@@ -352,7 +392,7 @@ public GriddlySettings<TRow> RowId(Expression<Func<TRow, object>> expression, st
352
392
return this ;
353
393
}
354
394
355
- 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 , int defaultSortOrder = 0 )
395
+ 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 , Func < TRow , object > htmlAttributes = null , object headerHtmlAttributes = null , int defaultSortOrder = 0 )
356
396
{
357
397
ModelMetadata metadata = null ;
358
398
@@ -401,6 +441,9 @@ public GriddlySettings<TRow> Column<TProperty>(Expression<Func<TRow, TProperty>>
401
441
if ( string . IsNullOrWhiteSpace ( expressionString ) && summaryFunction != null )
402
442
throw new InvalidOperationException ( "Must specify an expression to use a summary function." ) ;
403
443
444
+ if ( headerHtmlAttributes != null && ! ( headerHtmlAttributes is IDictionary < string , object > ) )
445
+ headerHtmlAttributes = HtmlHelper . AnonymousObjectToHtmlAttributes ( headerHtmlAttributes ) ;
446
+
404
447
Add ( new GriddlyColumn < TRow > ( )
405
448
{
406
449
Template = template ,
@@ -413,15 +456,17 @@ public GriddlySettings<TRow> Column<TProperty>(Expression<Func<TRow, TProperty>>
413
456
DefaultSortOrder = defaultSortOrder ,
414
457
ClassName = className ,
415
458
IsExportOnly = isExportOnly ,
416
- Width = width
459
+ Width = width ,
460
+ HtmlAttributesTemplate = htmlAttributes ,
461
+ HeaderHtmlAttributes = ( IDictionary < string , object > ) headerHtmlAttributes
417
462
} , filter ) ;
418
463
419
464
return this ;
420
465
}
421
466
422
- public GriddlySettings < TRow > Column ( 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 , int defaultSortOrder = 0 )
467
+ public GriddlySettings < TRow > Column ( 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 , Func < TRow , object > htmlAttributes = null , object headerHtmlAttributes = null , int defaultSortOrder = 0 )
423
468
{
424
- return Column < object > ( null , caption , format , expressionString , defaultSort , className , isExportOnly , width , summaryFunction , summaryValue , template , filter , defaultSortOrder ) ;
469
+ return Column < object > ( null , caption , format , expressionString , defaultSort , className , isExportOnly , width , summaryFunction , summaryValue , template , filter , htmlAttributes , headerHtmlAttributes , defaultSortOrder ) ;
425
470
}
426
471
427
472
public GriddlySettings < TRow > SelectColumn ( Expression < Func < TRow , object > > id , object summaryValue = null )
0 commit comments