Example #1
0
        public override void ChangeValue(DateTime value, int index = 0)
        {
            if (index != 0)
            {
                throw new ArgumentOutOfRangeException("DatePicker should have only single picker.");
            }
            UseDefaultPickerValue[0] = false;

            CurrentValue = THelper.ChangeType <TValue>(value);

            _pickerStatus[0]._hadSelectValue = true;

            if (!IsShowTime && Picker != DatePickerType.Time)
            {
                Close();
            }

            if (OnChange.HasDelegate)
            {
                OnChange.InvokeAsync(new DateTimeChangedEventArgs
                {
                    Date       = value,
                    DateString = GetInputValue(0)
                });
            }
        }
        private static Func <T, T, T> BuildAggregateFunction()
        {
            var type           = typeof(T);
            var enumType       = THelper.GetUnderlyingType <T>();
            var underlyingType = Enum.GetUnderlyingType(enumType);
            var param1         = Expression.Parameter(type);
            var param2         = Expression.Parameter(type);
            var body           = Expression.Convert(
                Expression.Or(
                    Expression.Convert(param1, underlyingType),
                    Expression.Convert(param2, underlyingType)),
                type);

            return(Expression.Lambda <Func <T, T, T> >(body, param1, param2).Compile());
        }
Example #3
0
        protected override void OnInitialized()
        {
            base.OnInitialized();

            Sortable = Sortable || SorterMultiple != default || SorterCompare != default || DefaultSortOrder != default || SortDirections?.Any() == true;

            if (IsHeader)
            {
                if (FieldExpression != null)
                {
                    var paramExp = Expression.Parameter(ItemType);
                    var member   = ColumnExpressionHelper.GetReturnMemberInfo(FieldExpression);
                    var bodyExp  = Expression.MakeMemberAccess(paramExp, member);
                    GetFieldExpression = Expression.Lambda(bodyExp, paramExp);
                }
                else if (DataIndex != null)
                {
                    (_, GetFieldExpression) = ColumnDataIndexHelper <TData> .GetDataIndexConfig(this);
                }

                if (GetFieldExpression != null)
                {
                    var member = ColumnExpressionHelper.GetReturnMemberInfo(GetFieldExpression);
                    DisplayName = member.GetCustomAttribute <DisplayNameAttribute>(true)?.DisplayName ?? member.GetCustomAttribute <DisplayAttribute>(true)?.GetName() ?? member.Name;
                    FieldName   = DataIndex ?? member.Name;
                }

                if (Sortable && GetFieldExpression != null)
                {
                    SortModel = new SortModel <TData>(GetFieldExpression, FieldName, SorterMultiple, DefaultSortOrder, SorterCompare);
                }
            }
            else if (IsBody)
            {
                SortModel = Context.HeaderColumns[ColIndex] is IFieldColumn fieldColumn ? fieldColumn.SortModel : null;

                (GetValue, _) = ColumnDataIndexHelper <TData> .GetDataIndexConfig(this);
            }

            SortDirections ??= Table.SortDirections;

            Sortable       = Sortable || SortModel != null;
            _sortDirection = SortModel?.SortDirection ?? DefaultSortOrder ?? SortDirection.None;

            if (Filters?.Any() == true)
            {
                Filterable        = true;
                _columnFilterType = TableFilterType.List;
            }
            else if (Filterable)
            {
                _columnDataType = THelper.GetUnderlyingType <TData>();
                if (_columnDataType == typeof(bool))
                {
                    _columnFilterType = TableFilterType.List;

                    Filters = new List <TableFilter <TData> >();

                    var trueFilterOption = GetNewFilter();
                    trueFilterOption.Text  = Table.Locale.FilterOptions.True;
                    trueFilterOption.Value = THelper.ChangeType <TData>(true);
                    ((List <TableFilter <TData> >)Filters).Add(trueFilterOption);
                    var falseFilterOption = GetNewFilter();
                    falseFilterOption.Text  = Table.Locale.FilterOptions.False;
                    falseFilterOption.Value = THelper.ChangeType <TData>(false);
                    ((List <TableFilter <TData> >)Filters).Add(falseFilterOption);
                }
                else
                {
                    _columnFilterType = TableFilterType.FeildType;
                    InitFilters();
                }
            }

            ClassMapper
            .If("ant-table-column-has-sorters", () => Sortable)
            .If($"ant-table-column-sort", () => Sortable && SortModel != null && SortModel.SortDirection.IsIn(SortDirection.Ascending, SortDirection.Descending));
        }
 static EnumHelper()
 {
     _enumType          = THelper.GetUnderlyingType <T>();
     _aggregateFunction = BuildAggregateFunction();
     _valueList         = Enum.GetValues(_enumType).Cast <T>();
 }