public static IQueryable <T> DynamicSort <T, TKey>(this IQueryable <T> query, string sortExpression, Expression <Func <T, TKey> > defaultSorting, SortDirections defaultDirection) { if (sortExpression.IsNullOrWhiteSpace() && defaultSorting != null) { switch (defaultDirection) { case SortDirections.DESC: query = query.OrderByDescending(defaultSorting); break; case SortDirections.ASC: default: query = query.OrderBy(defaultSorting); break; } } else { query = query.OrderBy(sortExpression); } return(query); }
/// <summary>Initializes a new instance of the <see cref="LVQuickSort" /> class.</summary> public LVQuickSort() { _numericCompare = false; _stopRequested = false; _sortColumn = 0; _sortDirection = SortDirections.Descending; }
public Column( string id, string displayName, bool shown, string width, bool monospace, SortDirections sortDirection, int sortIndex, string filterValue, bool filterable, bool sortable, PropertyInfo?property ) { if (!_matchSize.IsMatch(width)) { throw new ArgumentException($"Size '{width}' is not a valid CSS element size.", nameof(width)); } DisplayName = displayName; FilterValue = filterValue; ID = id; Property = property; Shown = shown; Width = width; Monospace = monospace; SortDirection = sortDirection; SortIndex = sortIndex; Filterable = filterable; Sortable = sortable; }
public static IQueryable <T> SortAndTake <T, TKey>(this IQueryable <T> query, string sortExpression, int page, int pageSize, Expression <Func <T, TKey> > defaultSorting, SortDirections defaultDirection) { return(query.DynamicSort(sortExpression, defaultSorting, defaultDirection) .SkipAndTake(page, pageSize)); }
public SortingNode(string memberPath, Type dataType, DataTypeCode dataTypeCode, SortDirections direction = SortDirections.Asc) { Ensure.That(memberPath, "memberPath").IsNotNullOrWhiteSpace(); Ensure.That(dataType, "dataType").IsNotNull(); MemberPath = memberPath; DataType = dataType; DataTypeCode = dataTypeCode; Direction = direction; }
public SortingNode(string memberPath, Type dataType, DataTypeCode dataTypeCode, SortDirections direction = SortDirections.Asc) { Ensure.That(memberPath, "memberPath").IsNotNullOrWhiteSpace(); Ensure.That(dataType, "dataType").IsNotNull(); MemberPath = memberPath; DataType = dataType; DataTypeCode = dataTypeCode; Direction = direction; }
public void RegisterColumn( string id, string?displayName = null, bool shown = true, SortDirections sortDirection = SortDirections.Neutral, string filterValue = "", string width = "unset", bool monospace = false, bool filterable = true, bool sortable = true ) { if (_columns.Contains(id)) { throw new ArgumentException($"Column ID '{id}' is already registered.", nameof(id)); } PropertyInfo?t = null; if (_usingReflectionValueGetter && (filterable || sortable)) { t = typeof(T).GetProperty(id); if (t == null) { throw new ArgumentException($"Property ID '{id}' does not exist in type '{typeof(T).FullName}'."); } } Column c = new Column ( id, displayName ?? id, shown, width, monospace, sortDirection, sortDirection == SortDirections.Neutral ? 0 : _currentSortIndex++, filterValue, filterable, sortable, t ); c.Default = c.Clone(); if (RegexMode) { c.TryCompileFilter(); } _columns.Add(id, c); _matchedRowCache = null; _sortedRowCache = null; }
/// <summary>Initializes a new instance of the <see cref="VisualListViewColumn" /> class.</summary> public VisualListViewColumn() { embeddedType = LVActivatedEmbeddedTypes.None; _activeControlItems = new ArrayList(); _columnState = ColumnStates.None; _imageIndex = -1; _lastSortDirection = SortDirections.Descending; _textAlignment = ContentAlignment.MiddleLeft; _width = 100; _tag = null; }
public async Task SetColumnSort(string id, SortDirections sortDirection, int index) { Column c = (Column)_columns[id]; c.SortDirection = sortDirection; c.SortIndex = index; await StoreColumnConfig((Column)_columns[id]); _sortedRowCache = null; OnColumnSortUpdate.Invoke(); ExecutePending(); }
public static string ToShortString(this SortDirections sort) { switch (sort) { case SortDirections.Ascending: return("asc"); case SortDirections.Descending: return("desc"); default: return("none"); } }
public void ChangeSorting(string columnName, SortDirections sortDirection) { RemoveEditorFromControls(false); var newSortedColumns = Columns.Select(k => k).Where(u => u.HeaderText == columnName).ToList(); foreach (var item in newSortedColumns) { if (item.Visible) { _API.SortedColumnIndex = item.Index; _API.SortDirection = sortDirection; break; } } }
/// <summary> /// Do a property sort on a specific property. /// </summary> /// <typeparam name="TEntity"></typeparam> /// <typeparam name="TKey"></typeparam> /// <param name="items"></param> /// <param name="keySelectorExpression"></param> /// <param name="direction"></param> /// <returns></returns> public static IQueryable <TEntity> WithPropertySort <TEntity, TKey>(this IQueryable <TEntity> items, Expression <Func <TEntity, TKey> > keySelectorExpression, SortDirections direction = SortDirections.None) { switch (direction) { case SortDirections.Ascending: return(items.OrderBy(keySelectorExpression)); case SortDirections.Descending: return(items.OrderByDescending(keySelectorExpression)); default: return(items); } }
/// <summary>Initializes a new instance of the <see cref="VisualListViewColumn" /> class.</summary> public VisualListViewColumn() { _embeddedControlTemplate = null; _embeddedType = LVActivatedEmbeddedTypes.None; _activeControlItems = new ArrayList(); _columnState = ColumnStates.None; _imageIndex = -1; _lastSortDirection = SortDirections.Descending; _textAlignment = ContentAlignment.MiddleLeft; _width = 100; _tag = null; _listView = null; _numericSort = false; _checked = false; _checkBoxes = false; _checkBox = false; }
/// <summary> /// Vertex sorting is implement through an index look-up table /// </summary> public void UpdateVertexSorting(SortDirections sortDirection) { SortedVertexIndices = Enumerable.Range(0, _distinctVertices.Count).ToList(); switch (sortDirection) { case SortDirections.XForward: SortedVertexIndices.Sort((v1, v2) => Positions[_distinctVertices[v1].PositionIndex].X. CompareTo(Positions[_distinctVertices[v2].PositionIndex].X)); break; case SortDirections.XBackwards: SortedVertexIndices.Sort((v1, v2) => Positions[_distinctVertices[v2].PositionIndex].X. CompareTo(Positions[_distinctVertices[v1].PositionIndex].X)); break; case SortDirections.YForward: SortedVertexIndices.Sort((v1, v2) => Positions[_distinctVertices[v1].PositionIndex].Y. CompareTo(Positions[_distinctVertices[v2].PositionIndex].Y)); break; case SortDirections.YBackwards: SortedVertexIndices.Sort((v1, v2) => Positions[_distinctVertices[v2].PositionIndex].Y. CompareTo(Positions[_distinctVertices[v1].PositionIndex].Y)); break; case SortDirections.ZForward: SortedVertexIndices.Sort((v1, v2) => Positions[_distinctVertices[v1].PositionIndex].Z. CompareTo(Positions[_distinctVertices[v2].PositionIndex].Z)); break; case SortDirections.ZBackwards: SortedVertexIndices.Sort((v1, v2) => Positions[_distinctVertices[v2].PositionIndex].Z. CompareTo(Positions[_distinctVertices[v1].PositionIndex].Z)); break; case SortDirections.Ignore: break; } }
private ActionResult GetSortedProjectsModel(Guid _UserId, SortDirections _sortValue, SortItems _element, int pageNumber, int itemsPerPage) { ProjectsManager pm = new ProjectsManager(); //Obtaining values List <string> _TypesOptions = pm.getProjectTypesOptions(); List <string> _StatusesOptions = pm.getProjectStatusOptions(); List <string> _BakupOptions = pm.getBackUpPlanOptions(); List <string> _PMOptions = pm.getPMOptions(); List <string> _DevOptions = pm.getDevsOptions(); List <string> _DesgnsOptions = pm.getDesgnsOptions(); var prjcts = GetProjectsFromDb(_UserId); List <ProjectsModel> OrderedProjects = SortAndOrderProjects(_element, _sortValue, prjcts); var pmd = new ProjectsModel { SortItem = _element, SortDirection = _sortValue, UserId = _UserId, CampaignItems = OrderedProjects .Skip(((pageNumber == 0 ? 1 : pageNumber) - 1) * (itemsPerPage == 0 ? 10 : itemsPerPage)) .Take(itemsPerPage == 0 ? 10 : itemsPerPage).ToList(), Devs = _DevOptions, Desgns = _DesgnsOptions, PMs = _PMOptions, Types = _TypesOptions, Statuses = _StatusesOptions, BackUpOptions = _BakupOptions, projectNo = prjcts.Count(), PageNo = (pageNumber == 0 ? 1 : pageNumber), NoPages = prjcts.Distinct().Count() / (itemsPerPage == 0 ? 10 : itemsPerPage) + (prjcts.Distinct().Count() % (itemsPerPage == 0 ? 10 : itemsPerPage) > 0 ? 1 : 0) }; return(PartialView("_tablePartial", pmd)); }
/// <summary>Initializes a new instance of the <see cref="LVMergeSort" /> class.</summary> public LVMergeSort() { _sortDirection = SortDirections.Descending; }
public ActionResult Paging(int _pageNO, SortDirections _sortValue, SortItems _element, Guid _UserId) { return(GetSortedProjectsModel(_UserId, _sortValue, _element, _pageNO, 0)); }
private static List <ProjectsModel> SortAndOrderProjects(SortItems _headerValue, SortDirections sortDirection, IEnumerable <ProjectsModel> prjcts) { List <ProjectsModel> OrderedProjects; switch (_headerValue) { default: OrderedProjects = sortDirection == SortDirections.Ascending ? prjcts.OrderBy(x => x.ProjectName).ToList() : prjcts.OrderByDescending(x => x.ProjectName).ToList(); break; case SortItems.Client: OrderedProjects = sortDirection == SortDirections.Ascending ? prjcts.OrderBy(x => x.ClientName).ToList() : prjcts.OrderByDescending(x => x.ClientName).ToList(); break; //=================================NOT CURRENTLY USED======================================// case SortItems.Manager: OrderedProjects = prjcts.OrderByDescending(x => x.ProjectManager).ToList(); break; case SortItems.Developer: OrderedProjects = prjcts.OrderByDescending(x => x.Developer).ToList(); break; case SortItems.Designer: OrderedProjects = prjcts.OrderByDescending(x => x.Designer).ToList(); break; case SortItems.ProjectType: OrderedProjects = prjcts.OrderByDescending(x => x.ProjectType).ToList(); break; case SortItems.ProjectStatus: OrderedProjects = prjcts.OrderByDescending(x => x.Status).ToList(); break; case SortItems.BackupPlan: OrderedProjects = prjcts.OrderByDescending(x => x.BackUp).ToList(); break; case SortItems.Value: OrderedProjects = prjcts.OrderByDescending(x => x.ProjectValue).ToList(); break; } return(OrderedProjects); }
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)); }
public ActionResult sortTable(Guid userId, SortItems _headerValue, SortDirections sortDirection) { return(GetSortedProjectsModel(userId, sortDirection, _headerValue, 0, 0)); }
/// <summary> /// Получить список экземпляров сущности. /// </summary> /// <param name="_entityId">Идентификатор сущности.</param> /// <param name="sort_FieldId">Идентификатор поля для сортировки.</param> /// <param name="sortDirection">Идентификатор направления сортировки.</param> /// <param name="filters">Фильтры.</param> /// <param name="pageSize">Размер страницы.</param> /// <param name="pageNumber">Номер страницы.</param> /// <returns>Список обобщенных сущностей.</returns> public List <_GenericEntity> GetEntitiesList( int _entityId, int?sort_FieldId = null, SortDirections sortDirection = SortDirections.Ascending, List <_GenericEntityFieldFilter> filters = null, int pageSize = 1000, int pageNumber = 0) { using (var uow = this.CreateAdminUnitOfWork()) { _Entity entity = uow._EntityRepository.GetById(_entityId); List <_Field> fields = uow._FieldRepository.Query(entityId: _entityId); _Field sortField = fields.FirstOrDefault(f => f.Id == sort_FieldId) ?? fields.First(); IEnumerable <string> selectList = fields.Select(f => { switch (f._FieldTypeId) { case (int)_FieldTypes.Integer: case (int)_FieldTypes.Decimal: return($"CAST({f.DatabaseName} AS TEXT) AS f_{f.Id}"); case (int)_FieldTypes.DateTime: return($"TO_CHAR({f.DatabaseName}, '{SQL_DATE_TIME_FORMAT}') AS f_{f.Id}"); default: return($"{f.DatabaseName} AS f_{f.Id}"); } }); filters = filters ?? new List <_GenericEntityFieldFilter>(); IEnumerable <string> filterList = filters.Select(f => { var field = fields.FirstOrDefault(x => x.Id == f._FieldId); Argument.Require(field != null, "Не найдено поле сущности для фильтра."); object deserializedValue = _DeserializeField(f.Value, field._FieldTypeId); string sqlValue = _ToSqlField(deserializedValue, field._FieldTypeId); return($"{field.DatabaseName} = {sqlValue}"); }); string query = $"SELECT " + $"{Environment.NewLine}{string.Join($"{Environment.NewLine}, ", selectList)} " + $"{Environment.NewLine}FROM {entity.DatabaseScheme}.\"{entity.DatabaseName}\" " + (!filterList.Any() ? "" : $"{Environment.NewLine}WHERE {string.Join($"{Environment.NewLine} AND ", filterList)} ") + $"{Environment.NewLine}ORDER BY {sortField.DatabaseName} {sortDirection.GetDescription()} " + $"{Environment.NewLine}OFFSET {pageNumber} * {pageSize} LIMIT {pageSize};"; List <_GenericEntity> result = uow._DynamicRepository.Sql(query) .Select(e => { var ent = new _GenericEntity() { EntityId = _entityId }; ent.Fields = e .Select(f => { var fieldId = Int32.Parse(f.Key.Replace("f_", "")); var field = fields.FirstOrDefault(x => x.Id == fieldId); return(new _GenericEntityField() { FieldId = fieldId, _FieldTypeId = field._FieldTypeId, Value = f.Value as string }); }) .ToList(); return(ent); }) .ToList(); return(result); } }
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 (Sortable && GetFieldExpression != null) { SortModel = new SortModel <TData>(GetFieldExpression, SorterMultiple, DefaultSortOrder, SorterCompare); } if (GetFieldExpression != null) { var member = ColumnExpressionHelper.GetReturnMemberInfo(GetFieldExpression); DisplayName = member.GetCustomAttribute <DisplayNameAttribute>(true)?.DisplayName ?? member.Name; FieldName = member.Name; } } 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; ClassMapper .If("ant-table-column-has-sorters", () => Sortable) .If($"ant-table-column-sort", () => Sortable && SortModel != null && SortModel.SortDirection.IsIn(SortDirection.Ascending, SortDirection.Descending)); }
public static IQueryable <TEntity> Order <TEntity>(this IQueryable <TEntity> source, SortDirections direction, string[] properties) { string o; switch (direction) { case SortDirections.ZtoA: o = "Descending"; break; default: o = string.Empty; break; } var type = typeof(TEntity); var parameter = Expression.Parameter(type, "e"); var order = "OrderBy" + o; var result = source; foreach (var property in properties) { Type propertyType; var propertyAccess = MakeMemberAccess(type, parameter, property, out propertyType); var orderByExpression = Expression.Lambda(propertyAccess, parameter); var resultExpression = Expression.Call(typeof(Queryable), order, new[] { type, propertyType }, result.Expression, Expression.Quote(orderByExpression)); result = result.Provider.CreateQuery <TEntity>(resultExpression); order = "ThenBy" + o; } return(result); }
// this constructor is automatically called during deserialization public DataGridColumn(SerializationInfo info, StreamingContext context) : base(info, context) { foreach (SerializationEntry entry in info) { switch (entry.Name) { case "Position": m_Position = (int)entry.Value; break; case "Visible": m_Visible = (bool)entry.Value; break; case "Width": m_Width = (float)entry.Value; break; case "MinWidth": m_MinWidth = (int)entry.Value; break; case "IsTreeColumn": m_IsTreeColumn = (bool)entry.Value; break; case "Scope": m_ColumnScope = (ColumnScopes)entry.Value; break; case "DisplayFormatString": m_DisplayFormatString = (string)entry.Value; break; case "EditFormatString": m_EditFormatString = (string)entry.Value; break; case "TextAlignment": m_TextAlignment = (Alignment)entry.Value; break; case "LineAlignment": m_LineAlignment = (Alignment)entry.Value; break; case "EditType": m_EditType = (EditTypes)entry.Value; break; case "CanEdit": m_CanEdit = (bool)entry.Value; break; case "AllowResize": m_AllowResize = (bool)entry.Value; break; case "AllowSort": m_AllowSort = (bool)entry.Value; break; case "SortDirection": m_SortDirection = (SortDirections)entry.Value; break; case "AutoMinWidth": m_AutoMinWidth = (bool)entry.Value; break; case "ValueList": m_ValueList = (List <ValueListItem>)entry.Value; break; case "AllowNull": m_AllowNull = (bool)entry.Value; break; case "DefaultValue": try { m_DefaultValue = entry.Value; } catch (SerializationException) { m_DefaultValue = null; } catch (Exception) { m_DefaultValue = null; } break; case "ValueType": ValueType = entry.Value as Type; break; } } }
/// <summary> /// Creates a new instance of this class. /// </summary> /// <param name="expression">Expression to use when sorting data.</param> /// <param name="direction">Sorting direction.</param> public SortExpression(IExpression expression, SortDirections direction = SortDirections.Ascending) { Expression = expression; Direction = direction; }
public IndexAttribute(bool isUnique = false, SortDirections sortDirection = SortDirections.asc, string indexedColumns = "") { IsUnique = isUnique; SortDirection = sortDirection; IndexedColumns = indexedColumns; }
public PrimaryKeyAttribute(bool autoInc = false, SortDirections sortDirection = SortDirections.asc) { AutoInc = autoInc; SortDirection = sortDirection; }
protected override void OnInitialized() { base.OnInitialized(); Sortable = Sortable || SorterMultiple != default || SorterCompare != default || DefaultSortOrder != default || SortDirections?.Any() == true; if (IsHeader) { if (FieldExpression != null) { _propertyReflector = PropertyReflector.Create(FieldExpression); } if (Sortable) { if (_propertyReflector.HasValue) { SortModel = new SortModel <TData>(_propertyReflector.Value.PropertyInfo, SorterMultiple, DefaultSortOrder, SorterCompare); } else { (GetValue, SortModel) = ColumnDataIndexHelper <TData> .GetDataIndexConfig(this); } } } 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; ClassMapper .If("ant-table-column-has-sorters", () => Sortable) .If($"ant-table-column-sort", () => Sortable && SortModel != null && SortModel.SortDirection.IsIn(SortDirection.Ascending, SortDirection.Descending)); }
public static IQueryable <TEntity> Order <TEntity>(this IQueryable <TEntity> source, SortDirections direction, string ordering) { if (ordering.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Length > 1) { return(source.Order(direction, ordering.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))); } string order; switch (direction) { case SortDirections.ZtoA: order = "OrderByDescending"; break; default: order = "OrderBy"; break; } var type = typeof(TEntity); var parameter = Expression.Parameter(type, "e"); Type propertyType; var propertyAccess = MakeMemberAccess(type, parameter, ordering, out propertyType); var orderByExpression = Expression.Lambda(propertyAccess, parameter); var resultExpression = Expression.Call(typeof(Queryable), order, new[] { type, propertyType }, source.Expression, Expression.Quote(orderByExpression)); return(source.Provider.CreateQuery <TEntity>(resultExpression)); }