/
RadzenDataGridColumn.cs
1006 lines (877 loc) · 33.2 KB
/
RadzenDataGridColumn.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Threading.Tasks;
namespace Radzen.Blazor
{
/// <summary>
/// RadzenDataGridColumn component.
/// Must be placed inside a <see cref="RadzenDataGrid{TItem}" />
/// </summary>
/// <typeparam name="TItem">The type of the DataGrid item.</typeparam>
public partial class RadzenDataGridColumn<TItem> : ComponentBase, IDisposable
{
/// <summary>
/// Gets or sets the grid.
/// </summary>
/// <value>The grid.</value>
[CascadingParameter]
public RadzenDataGrid<TItem> Grid { get; set; }
/// <summary>
/// Gets or sets the columns.
/// </summary>
/// <value>The columns.</value>
[Parameter]
public RenderFragment Columns { get; set; }
/// <summary>
/// Gets or sets the parent column.
/// </summary>
/// <value>The parent column.</value>
[CascadingParameter]
public RadzenDataGridColumn<TItem> Parent { get; set; }
internal void RemoveColumn(RadzenDataGridColumn<TItem> column)
{
if (Grid.childColumns.Contains(column))
{
Grid.childColumns.Remove(column);
if (!Grid.disposed)
{
try { InvokeAsync(StateHasChanged); } catch { }
}
}
}
internal int GetLevel()
{
int i = 0;
var p = Parent;
while (p != null)
{
p = p.Parent;
i++;
}
return i;
}
internal int GetColSpan(bool isDataCell = false)
{
if (!Grid.AllowCompositeDataCells && isDataCell)
return 1;
var directChildColumns = Grid.childColumns.Where(c => c.GetVisible() && c.Parent == this);
if (Parent == null)
{
return Columns == null ? 1 : directChildColumns.Sum(c => c.GetColSpan());
}
return Columns == null ? 1 : directChildColumns.Count();
}
internal int GetRowSpan(bool isDataCell = false)
{
if (!Grid.AllowCompositeDataCells && isDataCell)
return 1;
if (Columns == null && Parent != null)
{
var level = this.GetLevel();
return level == Grid.deepestChildColumnLevel ? 1 : level + 1;
}
return Columns == null && Parent == null ? Grid.deepestChildColumnLevel + 1 : 1;
}
/// <summary>
/// Called when initialized.
/// </summary>
protected override void OnInitialized()
{
if (Grid != null)
{
Grid.AddColumn(this);
var property = GetFilterProperty();
if (!string.IsNullOrEmpty(property) && Type == null)
{
if (!string.IsNullOrEmpty(property))
{
_filterPropertyType = PropertyAccess.GetPropertyType(typeof(TItem), property);
}
}
if (_filterPropertyType == null)
{
_filterPropertyType = Type;
}
else
{
propertyValueGetter = PropertyAccess.Getter<TItem, object>(Property);
}
if (_filterPropertyType == typeof(string))
{
FilterOperator = FilterOperator.Contains;
}
}
}
int? orderIndex;
/// <summary>
/// Gets or sets the order index.
/// </summary>
/// <value>The order index.</value>
[Parameter]
public int? OrderIndex { get; set; }
internal int? GetOrderIndex()
{
return orderIndex ?? OrderIndex;
}
internal void SetOrderIndex(int? value)
{
orderIndex = value;
}
/// <summary>
/// Gets or sets the sort order.
/// </summary>
/// <value>The sort order.</value>
[Parameter]
public SortOrder? SortOrder { get; set; }
bool visible = true;
/// <summary>
/// Gets or sets a value indicating whether this <see cref="RadzenDataGridColumn{TItem}"/> is visible.
/// </summary>
/// <value><c>true</c> if visible; otherwise, <c>false</c>.</value>
[Parameter]
public bool Visible
{
get
{
return visible;
}
set
{
if (visible != value)
{
visible = value;
if (Grid != null)
{
Grid.UpdatePickableColumn(this, visible);
InvokeAsync(Grid.ChangeState);
}
}
}
}
bool? _visible;
/// <summary>
/// Gets if the column is visible or not.
/// </summary>
/// <returns>System.Boolean.</returns>
public bool GetVisible()
{
return _visible ?? Visible;
}
internal void SetVisible(bool? value)
{
_visible = value;
if (Grid != null)
{
Grid.UpdatePickableColumn(this, _visible == true);
}
}
/// <summary>
/// Gets or sets the title.
/// </summary>
/// <value>The title.</value>
[Parameter]
public string Title { get; set; }
/// <summary>
/// Gets or sets the property name.
/// </summary>
/// <value>The property name.</value>
[Parameter]
public string Property { get; set; }
/// <summary>
/// Gets or sets the sort property name.
/// </summary>
/// <value>The sort property name.</value>
[Parameter]
public string SortProperty { get; set; }
/// <summary>
/// Gets or sets the group property name.
/// </summary>
/// <value>The group property name.</value>
[Parameter]
public string GroupProperty { get; set; }
/// <summary>
/// Gets or sets the filter property name.
/// </summary>
/// <value>The filter property name.</value>
[Parameter]
public string FilterProperty { get; set; }
/// <summary>
/// Gets or sets the filter value.
/// </summary>
/// <value>The filter value.</value>
[Parameter]
public object FilterValue { get; set; }
/// <summary>
/// Gets or sets the second filter value.
/// </summary>
/// <value>The second filter value.</value>
[Parameter]
public object SecondFilterValue { get; set; }
/// <summary>
/// Gets or sets the width.
/// </summary>
/// <value>The width.</value>
[Parameter]
public string Width { get; set; }
/// <summary>
/// Gets or sets the min-width.
/// </summary>
/// <value>The min-width.</value>
[Parameter]
public string MinWidth { get; set; }
/// <summary>
/// Gets or sets the format string.
/// </summary>
/// <value>The format string.</value>
[Parameter]
public string FormatString { get; set; }
/// <summary>
/// Gets or sets the CSS class applied to data cells.
/// </summary>
/// <value>The CSS class applied to data cells.</value>
[Parameter]
public string CssClass { get; set; }
/// <summary>
/// Gets or sets the header CSS class applied to header cell.
/// </summary>
/// <value>The header CSS class applied to header cell.</value>
[Parameter]
public string HeaderCssClass { get; set; }
/// <summary>
/// Gets or sets the footer CSS class applied to footer cell.
/// </summary>
/// <value>The footer CSS class applied to footer cell.</value>
[Parameter]
public string FooterCssClass { get; set; }
/// <summary>
/// Gets or sets the group footer CSS class applied to group footer cell.
/// </summary>
/// <value>The group footer CSS class applied to group footer cell.</value>
[Parameter]
public string GroupFooterCssClass { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this <see cref="RadzenDataGridColumn{TItem}"/> is filterable.
/// </summary>
/// <value><c>true</c> if filterable; otherwise, <c>false</c>.</value>
[Parameter]
public bool Filterable { get; set; } = true;
/// <summary>
/// Gets or sets a value indicating whether this <see cref="RadzenDataGridColumn{TItem}"/> is sortable.
/// </summary>
/// <value><c>true</c> if sortable; otherwise, <c>false</c>.</value>
[Parameter]
public bool Sortable { get; set; } = true;
/// <summary>
/// Gets or sets a value indicating whether this <see cref="RadzenDataGridColumn{TItem}"/> is frozen.
/// </summary>
/// <value><c>true</c> if frozen; otherwise, <c>false</c>.</value>
[Parameter]
public bool Frozen { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this <see cref="RadzenDataGridColumn{TItem}"/> is resizable.
/// </summary>
/// <value><c>true</c> if resizable; otherwise, <c>false</c>.</value>
[Parameter]
public bool Resizable { get; set; } = true;
/// <summary>
/// Gets or sets a value indicating whether this <see cref="RadzenDataGridColumn{TItem}"/> is reorderable.
/// </summary>
/// <value><c>true</c> if reorderable; otherwise, <c>false</c>.</value>
[Parameter]
public bool Reorderable { get; set; } = true;
/// <summary>
/// Gets or sets a value indicating whether this <see cref="RadzenDataGridColumn{TItem}"/> is groupable.
/// </summary>
/// <value><c>true</c> if groupable; otherwise, <c>false</c>.</value>
[Parameter]
public bool Groupable { get; set; } = true;
/// <summary>
/// Gets or sets a value indicating whether this <see cref="RadzenDataGridColumn{TItem}"/> is pickable - listed when DataGrid AllowColumnPicking is set to true.
/// </summary>
/// <value><c>true</c> if pickable; otherwise, <c>false</c>.</value>
[Parameter]
public bool Pickable { get; set; } = true;
/// <summary>
/// Gets or sets the text align.
/// </summary>
/// <value>The text align.</value>
[Parameter]
public TextAlign TextAlign { get; set; } = TextAlign.Left;
/// <summary>
/// Gets or sets the template.
/// </summary>
/// <value>The template.</value>
[Parameter]
public RenderFragment<TItem> Template { get; set; }
/// <summary>
/// Gets or sets the edit template.
/// </summary>
/// <value>The edit template.</value>
[Parameter]
public RenderFragment<TItem> EditTemplate { get; set; }
/// <summary>
/// Gets or sets the header template.
/// </summary>
/// <value>The header template.</value>
[Parameter]
public RenderFragment HeaderTemplate { get; set; }
/// <summary>
/// Gets or sets the footer template.
/// </summary>
/// <value>The footer template.</value>
[Parameter]
public RenderFragment FooterTemplate { get; set; }
/// <summary>
/// Gets or sets the group footer template.
/// </summary>
/// <value>The group footer template.</value>
[Parameter]
public RenderFragment<Group> GroupFooterTemplate { get; set; }
/// <summary>
/// Gets or sets the filter template.
/// </summary>
/// <value>The filter template.</value>
[Parameter]
public RenderFragment<RadzenDataGridColumn<TItem>> FilterTemplate { get; set; }
/// <summary>
/// Gets or sets the logical filter operator.
/// </summary>
/// <value>The logical filter operator.</value>
[Parameter]
public LogicalFilterOperator LogicalFilterOperator { get; set; } = LogicalFilterOperator.And;
/// <summary>
/// Gets or sets the data type.
/// </summary>
/// <value>The data type.</value>
[Parameter]
public Type Type { get; set; }
Func<TItem, object> propertyValueGetter;
/// <summary>
/// Gets the value for specified item.
/// </summary>
/// <param name="item">The item.</param>
/// <returns>System.Object.</returns>
public virtual object GetValue(TItem item)
{
var value = propertyValueGetter != null && !string.IsNullOrEmpty(Property) && !Property.Contains('.') ? propertyValueGetter(item) : !string.IsNullOrEmpty(Property) ? PropertyAccess.GetValue(item, Property) : "";
return !string.IsNullOrEmpty(FormatString) ? string.Format(FormatString, value, Grid?.Culture ?? CultureInfo.CurrentCulture) : Convert.ToString(value, Grid?.Culture ?? CultureInfo.CurrentCulture);
}
internal object GetHeader()
{
if (HeaderTemplate != null)
{
return HeaderTemplate;
}
else if (!string.IsNullOrEmpty(Title))
{
return Title;
}
else
{
return Property;
}
}
/// <summary>
/// Gets the cell style.
/// </summary>
/// <param name="forCell">if set to <c>true</c> [for cell].</param>
/// <param name="isHeaderOrFooterCell">if set to <c>true</c> [is header or footer cell].</param>
/// <returns>System.String.</returns>
public string GetStyle(bool forCell = false, bool isHeaderOrFooterCell = false)
{
var style = new List<string>();
var width = GetWidth();
if (width != null)
{
style.Add($"width:{width}");
}
else if (Grid != null && Grid.ColumnWidth != null)
{
style.Add($"width:{Grid.ColumnWidth}");
}
if (forCell && TextAlign != TextAlign.Left)
{
style.Add($"text-align:{Enum.GetName(typeof(TextAlign), TextAlign).ToLower()};");
}
if (forCell && IsFrozen())
{
var visibleColumns = Grid.ColumnsCollection.Where(c => c.GetVisible()).ToList();
var left = visibleColumns
.Where((c, i) => visibleColumns.IndexOf(this) > i && c.IsFrozen())
.Sum(c => {
var w = !string.IsNullOrEmpty(c.GetWidth()) ? c.GetWidth() : Grid.ColumnWidth;
var cw = 200;
if (!string.IsNullOrEmpty(w) && w.Contains("px"))
{
int.TryParse(w.Replace("px", ""), out cw);
}
return cw;
});
style.Add($"left:{left}px");
}
if ((isHeaderOrFooterCell && IsFrozen() || isHeaderOrFooterCell && !IsFrozen() || !isHeaderOrFooterCell && IsFrozen()) && Grid.ColumnsCollection.Where(c => c.GetVisible() && c.IsFrozen()).Any())
{
style.Add($"z-index:{(isHeaderOrFooterCell && IsFrozen() ? 2 : 1)}");
}
if (!string.IsNullOrEmpty(MinWidth))
{
style.Add($"min-width:{MinWidth}");
}
return string.Join(";", style);
}
internal bool IsFrozen()
{
return Frozen && Parent == null && Columns == null;
}
/// <summary>
/// Gets the sort property.
/// </summary>
/// <returns>System.String.</returns>
public string GetSortProperty()
{
if (!string.IsNullOrEmpty(SortProperty))
{
return SortProperty;
}
else
{
return Property;
}
}
internal string GetSortOrderAsString(bool isOData)
{
var property = GetSortProperty();
if (string.IsNullOrEmpty(property))
return "";
var p = isOData ? property.Replace('.', '/') : PropertyAccess.GetProperty(property);
return $"{p} {(GetSortOrder() == Radzen.SortOrder.Ascending ? "asc" : "desc")}";
}
internal void SetSortOrder(SortOrder? order)
{
var descriptor = Grid.sorts.Where(d => d.Property == GetSortProperty()).FirstOrDefault();
if (descriptor == null)
{
descriptor = new SortDescriptor() { Property = GetSortProperty() };
}
if (GetSortOrder() == null)
{
SetSortOrderInternal(Radzen.SortOrder.Ascending);
descriptor.SortOrder = Radzen.SortOrder.Ascending;
}
else if (GetSortOrder() == Radzen.SortOrder.Ascending)
{
SetSortOrderInternal(Radzen.SortOrder.Descending);
descriptor.SortOrder = Radzen.SortOrder.Descending;
}
else if (GetSortOrder() == Radzen.SortOrder.Descending)
{
SetSortOrderInternal(null);
if (Grid.sorts.Where(d => d.Property == GetSortProperty()).Any())
{
Grid.sorts.Remove(descriptor);
}
descriptor = null;
}
if (descriptor != null && !Grid.sorts.Where(d => d.Property == GetSortProperty()).Any())
{
Grid.sorts.Add(descriptor);
}
sortOrder = new SortOrder?[] { order };
}
internal void SetSortOrderInternal(SortOrder? order)
{
sortOrder = new SortOrder?[] { order };
}
internal void ResetSortOrder()
{
sortOrder = Enumerable.Empty<SortOrder?>();
SortOrder = null;
}
/// <summary>
/// Gets the group property.
/// </summary>
/// <returns>System.String.</returns>
public string GetGroupProperty()
{
if (!string.IsNullOrEmpty(GroupProperty))
{
return GroupProperty;
}
else
{
return Property;
}
}
/// <summary>
/// Gets the filter property.
/// </summary>
/// <returns>System.String.</returns>
public string GetFilterProperty()
{
if (!string.IsNullOrEmpty(FilterProperty))
{
return FilterProperty;
}
else
{
return Property;
}
}
Type _filterPropertyType;
/// <summary>
/// Gets the filter property type.
/// </summary>
public Type FilterPropertyType
{
get
{
return _filterPropertyType;
}
}
IEnumerable<SortOrder?> sortOrder = Enumerable.Empty<SortOrder?>();
object filterValue;
FilterOperator? filterOperator;
object secondFilterValue;
FilterOperator? secondFilterOperator;
LogicalFilterOperator? logicalFilterOperator;
/// <summary>
/// Set parameters as an asynchronous operation.
/// </summary>
/// <param name="parameters">The parameters.</param>
/// <returns>A Task representing the asynchronous operation.</returns>
public override async Task SetParametersAsync(ParameterView parameters)
{
if (parameters.DidParameterChange(nameof(Visible), Visible) ||
parameters.DidParameterChange(nameof(Title), Title))
{
if (Grid != null)
{
Grid.UpdatePickableColumn(this, parameters.GetValueOrDefault<bool>(nameof(Visible)));
await Grid.ChangeState();
}
}
if (parameters.DidParameterChange(nameof(OrderIndex), OrderIndex))
{
var newOrderIndex = parameters.GetValueOrDefault<int?>(nameof(OrderIndex));
if (newOrderIndex != orderIndex)
{
SetOrderIndex(newOrderIndex);
if (Grid != null)
{
Grid.UpdateColumnsOrder();
await Grid.ChangeState();
}
}
}
if (parameters.DidParameterChange(nameof(SortOrder), SortOrder))
{
sortOrder = new SortOrder?[] { parameters.GetValueOrDefault<SortOrder?>(nameof(SortOrder)) };
if (Grid != null)
{
var descriptor = Grid.sorts.Where(d => d.Property == GetSortProperty()).FirstOrDefault();
if (descriptor == null)
{
Grid.sorts.Add(new SortDescriptor() { Property = GetSortProperty(), SortOrder = sortOrder.FirstOrDefault() });
Grid._view = null;
}
}
}
if (parameters.DidParameterChange(nameof(FilterValue), FilterValue))
{
filterValue = parameters.GetValueOrDefault<object>(nameof(FilterValue));
if (FilterTemplate != null)
{
FilterValue = filterValue;
Grid.SaveSettings();
if (Grid.IsVirtualizationAllowed())
{
#if NET5_0_OR_GREATER
if (Grid.virtualize != null)
{
await Grid.virtualize.RefreshDataAsync();
}
#endif
}
else
{
await Grid.Reload();
}
return;
}
}
if (parameters.DidParameterChange(nameof(FilterOperator), FilterOperator))
{
filterOperator = parameters.GetValueOrDefault<FilterOperator>(nameof(FilterOperator));
}
if (parameters.DidParameterChange(nameof(SecondFilterValue), SecondFilterValue))
{
secondFilterValue = parameters.GetValueOrDefault<object>(nameof(SecondFilterValue));
}
if (parameters.DidParameterChange(nameof(SecondFilterOperator), SecondFilterOperator))
{
secondFilterOperator = parameters.GetValueOrDefault<FilterOperator>(nameof(SecondFilterOperator));
}
if (parameters.DidParameterChange(nameof(LogicalFilterOperator), LogicalFilterOperator))
{
logicalFilterOperator = parameters.GetValueOrDefault<LogicalFilterOperator>(nameof(LogicalFilterOperator));
}
await base.SetParametersAsync(parameters);
}
/// <summary>
/// Get column sort order.
/// </summary>
public SortOrder? GetSortOrder()
{
return sortOrder.Any() ? sortOrder.FirstOrDefault() : SortOrder;
}
/// <summary>
/// Get column filter value.
/// </summary>
public object GetFilterValue()
{
return filterValue ?? FilterValue;
}
/// <summary>
/// Get column filter operator.
/// </summary>
public FilterOperator GetFilterOperator()
{
return filterOperator ?? FilterOperator;
}
/// <summary>
/// Get column second filter value.
/// </summary>
public object GetSecondFilterValue()
{
return secondFilterValue ?? SecondFilterValue;
}
/// <summary>
/// Get column second filter operator.
/// </summary>
public FilterOperator GetSecondFilterOperator()
{
return secondFilterOperator ?? SecondFilterOperator;
}
/// <summary>
/// Get column logical filter operator.
/// </summary>
public LogicalFilterOperator GetLogicalFilterOperator()
{
return logicalFilterOperator ?? LogicalFilterOperator;
}
/// <summary>
/// Set column filter value.
/// </summary>
public void SetFilterValue(object value, bool isFirst = true)
{
if ((FilterPropertyType == typeof(DateTimeOffset) || FilterPropertyType == typeof(DateTimeOffset?)) && value != null && value is DateTime?)
{
DateTimeOffset? offset = DateTime.SpecifyKind((DateTime)value, DateTimeKind.Utc);
value = offset;
}
if (isFirst)
{
filterValue = value;
}
else
{
secondFilterValue = value;
}
}
internal bool CanSetFilterValue()
{
return GetFilterOperator() == FilterOperator.IsNull
|| GetFilterOperator() == FilterOperator.IsNotNull
|| GetFilterOperator() == FilterOperator.IsEmpty
|| GetFilterOperator() == FilterOperator.IsNotEmpty;
}
/// <summary>
/// Sets to default column filter values and operators.
/// </summary>
public void ClearFilters()
{
SetFilterValue(null);
SetFilterValue(null, false);
SetFilterOperator(null);
SetSecondFilterOperator(null);
FilterValue = null;
SecondFilterValue = null;
FilterOperator = typeof(System.Collections.IEnumerable).IsAssignableFrom(FilterPropertyType) ? FilterOperator.Contains : default(FilterOperator);
SecondFilterOperator = default(FilterOperator);
LogicalFilterOperator = default(LogicalFilterOperator);
}
/// <summary>
/// Gets or sets the filter operator.
/// </summary>
/// <value>The filter operator.</value>
[Parameter]
public FilterOperator FilterOperator { get; set; }
/// <summary>
/// Gets or sets the second filter operator.
/// </summary>
/// <value>The second filter operator.</value>
[Parameter]
public FilterOperator SecondFilterOperator { get; set; }
/// <summary>
/// Set column filter operator.
/// </summary>
public void SetFilterOperator(FilterOperator? value)
{
if (value == FilterOperator.IsEmpty || value == FilterOperator.IsNotEmpty || value == FilterOperator.IsNull || value == FilterOperator.IsNotNull)
{
filterValue = value == FilterOperator.IsEmpty || value == FilterOperator.IsNotEmpty ? string.Empty : null;
}
filterOperator = value;
}
/// <summary>
/// Set column second filter operator.
/// </summary>
public void SetSecondFilterOperator(FilterOperator? value)
{
if (value == FilterOperator.IsEmpty || value == FilterOperator.IsNotEmpty || value == FilterOperator.IsNull || value == FilterOperator.IsNotNull)
{
secondFilterValue = value == FilterOperator.IsEmpty || value == FilterOperator.IsNotEmpty ? string.Empty : null;
}
secondFilterOperator = value;
}
/// <summary>
/// Set column second logical operator.
/// </summary>
public void SetLogicalFilterOperator(LogicalFilterOperator value)
{
LogicalFilterOperator = value;
}
/// <summary>
/// Closes this column filter popup.
/// </summary>
public async Task CloseFilter()
{
await Grid.GetJSRuntime().InvokeVoidAsync("Radzen.closePopup", $"{Grid.PopupID}{GetFilterProperty()}");
}
string runtimeWidth;
/// <summary>
/// Set column width.
/// </summary>
public void SetWidth(string value)
{
runtimeWidth = value;
}
/// <summary>
/// Get column width.
/// </summary>
public string GetWidth()
{
return !string.IsNullOrEmpty(runtimeWidth) ? runtimeWidth : Width;
}
/// <summary>
/// Get possible column filter operators.
/// </summary>
public virtual IEnumerable<FilterOperator> GetFilterOperators()
{
if (PropertyAccess.IsEnum(FilterPropertyType))
return new FilterOperator[] { FilterOperator.Equals, FilterOperator.NotEquals };
if (PropertyAccess.IsNullableEnum(FilterPropertyType))
return new FilterOperator[] { FilterOperator.Equals, FilterOperator.NotEquals, FilterOperator.IsNull, FilterOperator.IsNotNull };
return Enum.GetValues(typeof(FilterOperator)).Cast<FilterOperator>().Where(o => {
var isStringOperator = o == FilterOperator.Contains || o == FilterOperator.DoesNotContain
|| o == FilterOperator.StartsWith || o == FilterOperator.EndsWith || o == FilterOperator.IsEmpty || o == FilterOperator.IsNotEmpty;
return FilterPropertyType == typeof(string) ? isStringOperator
|| o == FilterOperator.Equals || o == FilterOperator.NotEquals
|| o == FilterOperator.IsNull || o == FilterOperator.IsNotNull
: !isStringOperator;
});
}
internal string GetFilterOperatorText(FilterOperator filterOperator)
{
switch (filterOperator)
{
case FilterOperator.Contains:
return Grid?.ContainsText;
case FilterOperator.DoesNotContain:
return Grid?.DoesNotContainText;
case FilterOperator.EndsWith:
return Grid?.EndsWithText;
case FilterOperator.Equals:
return Grid?.EqualsText;
case FilterOperator.GreaterThan:
return Grid?.GreaterThanText;
case FilterOperator. GreaterThanOrEquals:
return Grid?.GreaterThanOrEqualsText;
case FilterOperator.LessThan:
return Grid?.LessThanText;
case FilterOperator.LessThanOrEquals:
return Grid?.LessThanOrEqualsText;
case FilterOperator.StartsWith:
return Grid?.StartsWithText;
case FilterOperator.NotEquals:
return Grid?.NotEqualsText;
case FilterOperator.IsNull:
return Grid?.IsNullText;
case FilterOperator.IsEmpty:
return Grid?.IsEmptyText;
case FilterOperator.IsNotNull:
return Grid?.IsNotNullText;
case FilterOperator.IsNotEmpty:
return Grid?.IsNotEmptyText;
default:
return $"{filterOperator}";
}
}
internal string GetFilterOperatorSymbol(FilterOperator filterOperator)
{
var symbol = Grid.FilterCaseSensitivity == FilterCaseSensitivity.CaseInsensitive ? "a" : "A";
switch (filterOperator)
{
case FilterOperator.Contains:
return $"*{symbol}*";
case FilterOperator.DoesNotContain:
return $"*{symbol}*";
case FilterOperator.StartsWith:
return $"{symbol}**";
case FilterOperator.EndsWith:
return $"**{symbol}";
case FilterOperator.Equals:
return "=";
case FilterOperator.GreaterThan:
return ">";
case FilterOperator.GreaterThanOrEquals:
return "≥";
case FilterOperator.LessThan:
return "<";
case FilterOperator.LessThanOrEquals:
return "≤";
case FilterOperator.NotEquals:
return "≠";
case FilterOperator.IsNull:
return "∅";
case FilterOperator.IsNotNull:
return "!∅";
case FilterOperator.IsEmpty:
return "= ''";
case FilterOperator.IsNotEmpty:
return "≠ ''";
default:
return $"{filterOperator}";
}
}
/// <summary>
/// Gets value indicating if the user can specify time in DateTime column filter.
/// </summary>
public virtual bool ShowTimeForDateTimeFilter()
{
return true;
}
/// <summary>
/// Disposes this instance.
/// </summary>