@@ -88,9 +88,15 @@ public static GriddlyFilterList FilterList(this GriddlyColumn column, IEnumerabl
88
88
89
89
itemsList . AddRange ( items ) ;
90
90
91
+ List < SelectListItem > selectableItemsList = new List < SelectListItem > ( ) ;
92
+
93
+ selectableItemsList . AddRange ( itemsList . Where ( x => ! ( x is SelectListItemGroup ) ) ) ;
94
+ selectableItemsList . AddRange ( itemsList . Where ( x => x is SelectListItemGroup ) . SelectMany ( x => ( ( SelectListItemGroup ) x ) . Items ) ) ;
95
+
91
96
if ( isMultiple && defaultSelectAll && defaultValue == null )
92
97
{
93
- foreach ( SelectListItem item in itemsList )
98
+ // TODO: set default value to all selected
99
+ foreach ( SelectListItem item in selectableItemsList )
94
100
item . Selected = true ;
95
101
}
96
102
else if ( ! isMultiple || defaultValue != null )
@@ -99,11 +105,11 @@ public static GriddlyFilterList FilterList(this GriddlyColumn column, IEnumerabl
99
105
{
100
106
IEnumerable defaultValues = defaultValue as IEnumerable ;
101
107
102
- if ( defaultValues == null )
108
+ if ( defaultValues == null || defaultValue is string )
103
109
{
104
110
string value = GetDefaultValueString ( defaultValue ) ;
105
111
106
- foreach ( SelectListItem item in itemsList )
112
+ foreach ( SelectListItem item in selectableItemsList )
107
113
item . Selected = item . Value == value ;
108
114
}
109
115
else
@@ -112,14 +118,15 @@ public static GriddlyFilterList FilterList(this GriddlyColumn column, IEnumerabl
112
118
{
113
119
string valueString = GetDefaultValueString ( value ) ;
114
120
115
- foreach ( SelectListItem item in itemsList . Where ( x => x . Value == valueString ) )
121
+ foreach ( SelectListItem item in selectableItemsList . Where ( x => x . Value == valueString ) )
116
122
item . Selected = true ;
117
123
}
118
124
}
119
125
}
120
126
else
121
127
{
122
- for ( int i = 0 ; i < itemsList . Count ; i ++ )
128
+ // TODO: set default value to all selected
129
+ for ( int i = 0 ; i < selectableItemsList . Count ; i ++ )
123
130
itemsList [ i ] . Selected = ( i == 0 ) ;
124
131
}
125
132
}
@@ -129,6 +136,7 @@ public static GriddlyFilterList FilterList(this GriddlyColumn column, IEnumerabl
129
136
Field = field ,
130
137
Default = defaultValue ,
131
138
Items = itemsList ,
139
+ SelectableItems = selectableItemsList ,
132
140
Name = name ,
133
141
IsMultiple = isMultiple ,
134
142
IsNoneAll = isNoneAll ,
@@ -183,35 +191,33 @@ public static GriddlyFilterList FilterEnum<T>(this GriddlyColumn column, T?[] de
183
191
return column . FilterList ( Extensions . ToSelectListItems < T > ( ) , defaultValue , isMultiple , defaultSelectAll , nullItemText , isNoneAll , field , name ) ;
184
192
}
185
193
186
- public static GriddlyFilterList FilterBool ( this GriddlyColumn column , bool isMultiple = false , bool defaultSelectAll = false , string nullItemText = null , bool isNoneAll = false , string trueLabel = "Yes" , string falseLabel = "No" , string field = null , string name = null )
194
+ public static GriddlyFilterList FilterBool ( this GriddlyColumn column , string trueLabel = "Yes" , string falseLabel = "No" , string nullItemText = null , bool isMultiple = false , bool defaultSelectAll = false , bool isNoneAll = false , string field = null , string name = null )
187
195
{
188
- return column . FilterBool ( ( object ) null , isMultiple , defaultSelectAll , nullItemText , isNoneAll , trueLabel , falseLabel , field , name ) ;
196
+ return column . FilterList ( BuildBoolItems ( trueLabel , falseLabel ) , ( object ) null , isMultiple , defaultSelectAll , nullItemText , isNoneAll , field , name ) ;
189
197
}
190
198
191
- public static GriddlyFilterList FilterBool ( this GriddlyColumn column , bool ? defaultValue , bool isMultiple = false , bool defaultSelectAll = false , string nullItemText = null , bool isNoneAll = false , string trueLabel = "Yes" , string falseLabel = "No" , string field = null , string name = null )
199
+ public static GriddlyFilterList FilterBool ( this GriddlyColumn column , bool ? defaultValue , string trueLabel = "Yes" , string falseLabel = "No" , string nullItemText = null , bool isMultiple = false , bool defaultSelectAll = false , bool isNoneAll = false , string field = null , string name = null )
192
200
{
193
- return column . FilterBool ( defaultValue , isMultiple , defaultSelectAll , nullItemText , isNoneAll , trueLabel , falseLabel , field , name ) ;
201
+ return column . FilterList ( BuildBoolItems ( trueLabel , falseLabel ) , defaultValue , isMultiple , defaultSelectAll , nullItemText , isNoneAll , field , name ) ;
194
202
}
195
203
196
- public static GriddlyFilterList FilterBool ( this GriddlyColumn column , bool [ ] defaultValue , bool isMultiple = false , bool defaultSelectAll = false , string nullItemText = null , bool isNoneAll = false , string trueLabel = "Yes" , string falseLabel = "No" , string field = null , string name = null )
204
+ public static GriddlyFilterList FilterBool ( this GriddlyColumn column , bool [ ] defaultValue , string trueLabel = "Yes" , string falseLabel = "No" , string nullItemText = null , bool isMultiple = false , bool defaultSelectAll = false , bool isNoneAll = false , string field = null , string name = null )
197
205
{
198
- return column . FilterBool ( defaultValue , isMultiple , defaultSelectAll , nullItemText , isNoneAll , trueLabel , falseLabel , field , name ) ;
206
+ return column . FilterList ( BuildBoolItems ( trueLabel , falseLabel ) , defaultValue , isMultiple , defaultSelectAll , nullItemText , isNoneAll , field , name ) ;
199
207
}
200
208
201
- public static GriddlyFilterList FilterBool ( this GriddlyColumn column , bool ? [ ] defaultValue , bool isMultiple = false , bool defaultSelectAll = false , string nullItemText = null , bool isNoneAll = false , string trueLabel = "Yes" , string falseLabel = "No" , string field = null , string name = null )
209
+ public static GriddlyFilterList FilterBool ( this GriddlyColumn column , bool ? [ ] defaultValue , string trueLabel = "Yes" , string falseLabel = "No" , string nullItemText = null , bool isMultiple = false , bool defaultSelectAll = false , bool isNoneAll = false , string field = null , string name = null )
202
210
{
203
- return column . FilterBool ( defaultValue , isMultiple , defaultSelectAll , nullItemText , isNoneAll , trueLabel , falseLabel , field , name ) ;
211
+ return column . FilterList ( BuildBoolItems ( trueLabel , falseLabel ) , defaultValue , isMultiple , defaultSelectAll , nullItemText , isNoneAll , field , name ) ;
204
212
}
205
213
206
- static GriddlyFilterList FilterBool ( this GriddlyColumn column , object defaultValue , bool isMultiple = false , bool defaultSelectAll = false , string nullItemText = null , bool isNoneAll = false , string trueLabel = "Yes" , string falseLabel = "No" , string field = null , string name = null )
214
+ static List < SelectListItem > BuildBoolItems ( string trueLabel , string falseLabel )
207
215
{
208
- List < SelectListItem > items = new List < SelectListItem > ( )
216
+ return new List < SelectListItem > ( )
209
217
{
210
218
new SelectListItem ( ) { Value = "True" , Text = trueLabel } ,
211
219
new SelectListItem ( ) { Value = "False" , Text = falseLabel } ,
212
220
} ;
213
-
214
- return column . FilterList ( items , defaultValue , isMultiple , defaultSelectAll , nullItemText , isNoneAll , field , name ) ;
215
221
}
216
222
}
217
223
}
0 commit comments