private void HandleVisibleColumnsChanged() { if (AssociatedObject == null) { return; } // Not using LINQ to improve UI responsiveness... // ReSharper disable once ForCanBeConvertedToForeach foreach (var columnName in _columnsName) { _columns[columnName].Visibility = Visibility.Hidden; } var visibleColumns = VisibleColumns.ToArray(); for (var i = 0; i < visibleColumns.Length; i++) { var column = _columns[visibleColumns[i]]; var oldIndex = AssociatedObject.Columns.IndexOf(column); var newIndex = i; column.Visibility = Visibility.Visible; if (oldIndex != newIndex) { AssociatedObject.Columns.RemoveAt(oldIndex); AssociatedObject.Columns.Insert(newIndex, column); } } }
/// <summary> /// Sets the displayed column settings to the given settings. /// </summary> /// <param name="columnSettings">A mapping of <see cref="Column"/>s to their visibility state.</param> public void SetVisibleColumns(IReadOnlyDictionary <Column, bool> columnSettings) { Contract.RequiresNotNull(columnSettings, nameof(columnSettings)); AvailableColumns.Clear(); VisibleColumns.Clear(); SelectedAvailableColumns.Clear(); SelectedVisibleColumns.Clear(); foreach (Column col in Enum.GetValues(typeof(Column))) { bool isVisible; if (!columnSettings.TryGetValue(col, out isVisible)) { isVisible = false; } if (isVisible) { VisibleColumns.Add(col); } else { AvailableColumns.Add(col); } } }
protected override void OnViewChange() { base.OnViewChange(); _inLabelEdit = false; availableFieldsTreeColumns.ViewEditor = ViewEditor; availableFieldsTreeColumns.RootColumn = ViewInfo.ParentColumn; availableFieldsTreeColumns.SublistId = ViewInfo.SublistId; availableFieldsTreeColumns.CheckedColumns = ListColumnsInView(); IList <DisplayColumn> gridColumns = ImmutableList.ValueOf(ViewEditor.ViewInfo.DisplayColumns.Where(col => !col.ColumnSpec.Hidden)); if (gridColumns.Count != VisibleColumns.Count) { gridColumns = VisibleColumns; } ListViewHelper.ReplaceItems(listViewColumns, gridColumns.Select(MakeListViewColumnItem).ToArray()); if (null != SelectedPaths) { var selectedIndexes = VisibleColumns .Select((col, index) => new KeyValuePair <DisplayColumn, int>(col, index)) .Where(kvp => SelectedPaths.Contains(kvp.Key.PropertyPath)) .Select(kvp => kvp.Value); ListViewHelper.SelectIndexes(listViewColumns, selectedIndexes); } UpdateButtons(); }
private void settings_SaveVisibleColumns(MenuItem mi, string colName) { try { if (theContextMenu.Items.Count - nBaseItems < dataGrid.Columns.Count) { return; } // Put the visible column names into an array List <string> saVisibleColumns = VisibleColumns.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList(); if (saVisibleColumns != null && saVisibleColumns.Count > 0 && saVisibleColumns[saVisibleColumns.Count - 1].StartsWith("-")) { saVisibleColumns.RemoveAt(saVisibleColumns.Count - 1); } // If the menu item is unchecked (column is not visible) if (!mi.IsChecked) { // Make the column visible by adding its name to the Visible Columns list saVisibleColumns.Add(colName); } else // Hide the column by removing its name from the VisibleColumns list if (saVisibleColumns.Contains(colName) && saVisibleColumns.Count > 1) { saVisibleColumns.Remove(colName); } VisibleColumns = String.Join(";", saVisibleColumns) + ";-" + dataGrid.FrozenColumnCount.ToString(); } catch (Exception ex) { StdErrOut(ex, MethodInfo.GetCurrentMethod().Name); } }
private void contextMenu_AddNewMenuItem(DataGridColumn col) { try { MenuItem menuItem = new MenuItem() { Header = col.Header.ToString().Replace("\n", " ").Replace("\r", " "), StaysOpenOnClick = true }; List <string> saVisibleColumns = new List <String>() { "" }; if (VisibleColumns != null) { saVisibleColumns = VisibleColumns.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList(); } //menuItem.Icon = new Image() { Source = Application.Current.Resources["Checkmark"] as ImageSource }; //((Image)menuItem.Icon).Visibility = (saVisibleColumns.Contains(menuItem.Header) || VisibleColumns == null) ? Visibility.Visible : Visibility.Collapsed; menuItem.IsChecked = (saVisibleColumns.Contains(menuItem.Header)); menuItem.Click += (sender, e) => { contextMenu_ColumnName_Click(sender); }; theContextMenu.Items.Add(menuItem); } catch (Exception ex) { StdErrOut(ex, MethodInfo.GetCurrentMethod().Name); } }
private void dataGrid_Loaded() { //try //{ groupBox_AttachHeaderUI(); contextMenu_BuildMenu(false); VisibleColumns_Initialize(); // Set Frozen columns List <string> saVisibleColumns = VisibleColumns.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList(); if (saVisibleColumns != null && saVisibleColumns.Count > 0 && saVisibleColumns[saVisibleColumns.Count - 1].StartsWith("-")) { if (dataGrid != null) { HeaderColumnIndex = Convert.ToInt16(saVisibleColumns[saVisibleColumns.Count - 1].Substring(1)); if (HeaderColumnIndex > 0) { mnuFreeze.IsChecked = true; } } } //} //catch (Exception ex) //{ StdErrOut(ex, MethodInfo.GetCurrentMethod().Name); } }
private void InitializeEditors() { ViewContext.HttpContext.Items["$SelfInitialize$"] = true; var dataItem = Editing.DefaultDataItem(); var htmlHelper = new GridHtmlHelper <T>(ViewContext, DataKeyStore); if (Editing.Mode != GridEditMode.InLine && Editing.Mode != GridEditMode.InCell) { var container = new HtmlElement("div").AddClass(UIPrimitives.Grid.InFormContainer); htmlHelper.EditorForModel(dataItem, Editing.TemplateName, Columns.OfType <IGridForeignKeyColumn>().Select(c => c.SerializeSelectList), Editing.AdditionalViewData).AppendTo(container); EditorHtml = container.InnerHtml; } else { var cellBuilderFactory = new GridCellBuilderFactory(); VisibleColumns.Each(column => { var cellBuilder = cellBuilderFactory.CreateEditCellBuilder(column, htmlHelper); var editor = cellBuilder.CreateCell(dataItem); column.EditorHtml = editor.InnerHtml; }); } ViewContext.HttpContext.Items.Remove("$SelfInitialize$"); }
private void MoveColumnsDown() { for (int i = SelectedVisibleColumns.Count - 1; i >= 0; i--) { int origIdx = VisibleColumns.IndexOf(SelectedVisibleColumns[i]); VisibleColumns.Move(origIdx, origIdx + 1); } }
private void MoveColumnsUp() { for (int i = 0; i < SelectedVisibleColumns.Count; i++) { int origIdx = VisibleColumns.IndexOf(SelectedVisibleColumns[i]); VisibleColumns.Move(origIdx, origIdx - 1); } }
private GridGroupingData CreateGroupingData() { return(new GridGroupingData { GetTitle = VisibleColumns.Cast <IGridColumn>().GroupTitleForMember, GroupDescriptors = DataSource.Groups, Messages = Grouping.Messages, UrlBuilder = UrlBuilder }); }
private void HideColumns() { // ToArray used to detach the selection collection while we change the lists. foreach (var col in SelectedVisibleColumns.ToArray()) { VisibleColumns.Remove(col); AvailableColumns.Add(col); } SelectedVisibleColumns.Clear(); }
internal void ApplyFixedRowVisualState(bool isfixed) { if (isfixed) { foreach (var cell in VisibleColumns.Select(column => column.ColumnElement as GridCell)) { if (cell.GridCellRegion != "LastColumnCell") { if (cell is GridIndentCell) { if ((cell as GridIndentCell).ColumnType == IndentColumnType.AfterExpander) { VisualStateManager.GoToState(cell, "Fixed_NormalCell", false); } } else { #if WPF if (DataGrid.useDrawing && cell is GridCaptionSummaryCell) { cell.GridCellRegion = "Fixed_NormalCell"; } #endif VisualStateManager.GoToState(cell, "Fixed_NormalCell", false); } } else { #if WPF if (DataGrid.useDrawing && cell is GridCaptionSummaryCell) { cell.GridCellRegion = "Fixed_LastCell"; } #endif VisualStateManager.GoToState(cell, "Fixed_LastCell", false); } } } else { foreach (var cell in VisibleColumns.Select(column => column.ColumnElement as GridCell)) { if (cell is GridIndentCell) { var indentCell = cell as GridIndentCell; indentCell.ApplyIndentVisualState(indentCell.ColumnType); } else { cell.ApplyGridCellVisualStates(cell.GridCellRegion); } } } }
protected override void OnPaint(PaintEventArgs e) { using (_renderer.LockGraphics(e.Graphics)) { // White Background _renderer.SetBrush(Color.White); _renderer.SetSolidPen(Color.White); _renderer.FillRectangle(e.ClipRectangle); // Lag frame calculations SetLagFramesArray(); List <RollColumn> visibleColumns; if (HorizontalOrientation) { CalculateHorizontalColumnPositions(VisibleColumns.ToList()); visibleColumns = VisibleColumns .Take(_horizontalColumnTops.Count(c => c < e.ClipRectangle.Height)) .ToList(); } else { visibleColumns = _columns.VisibleColumns .Where(c => c.Right > _hBar.Value) .Where(c => c.Left - _hBar.Value < e.ClipRectangle.Width) .ToList(); } var firstVisibleRow = Math.Max(FirstVisibleRow, 0); var visibleRows = HorizontalOrientation ? e.ClipRectangle.Width / CellWidth : e.ClipRectangle.Height / CellHeight; var lastVisibleRow = firstVisibleRow + visibleRows; var needsColumnRedraw = HorizontalOrientation || e.ClipRectangle.Y < ColumnHeight; if (visibleColumns.Any() && needsColumnRedraw) { DrawColumnBg(visibleColumns, e.ClipRectangle); DrawColumnText(visibleColumns); } // Background DrawBg(visibleColumns, e.ClipRectangle, firstVisibleRow, lastVisibleRow); // Foreground DrawData(visibleColumns, firstVisibleRow, lastVisibleRow); DrawColumnDrag(visibleColumns); DrawCellDrag(visibleColumns); } }
private GridGroupingData CreateGroupingData() { return(new GridGroupingData { GetTitle = VisibleColumns.Cast <IGridColumn>().GroupTitleForMember, GroupDescriptors = DataProcessor.GroupDescriptors, Hint = Localization.GroupHint, UrlBuilder = UrlBuilder, SortedAscText = Localization.SortedAsc, SortedDescText = Localization.SortedDesc, UnGroupText = Localization.UnGroup }); }
public void AddColumn(PropertyPath propertyPath) { List<ColumnSpec> columnSpecs = new List<ColumnSpec>(VisibleColumns.Select(col=>col.ColumnSpec)); var newColumn = new ColumnSpec(propertyPath); if (listViewColumns.SelectedIndices.Count == 0) { columnSpecs.Add(newColumn); } else { columnSpecs.Insert(listViewColumns.SelectedIndices.Cast<int>().Min(), newColumn); } ColumnSpecs = columnSpecs; }
private void settings_SaveFrozenColumnCount() { try { List <string> saVisibleColumns = VisibleColumns.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList(); if (saVisibleColumns != null && saVisibleColumns.Count > 0 && saVisibleColumns[saVisibleColumns.Count - 1].StartsWith("-")) { saVisibleColumns.RemoveAt(saVisibleColumns.Count - 1); } VisibleColumns = String.Join(";", saVisibleColumns) + ";-" + dataGrid.FrozenColumnCount.ToString(); } catch (Exception ex) { StdErrOut(ex, MethodInfo.GetCurrentMethod().Name); } }
// TODO: this shouldn't be exposed. But in order to not expose it, each RollColumn must have a change callback, and all property changes must call it, it is quicker and easier to just call this when needed public void ColumnsChanged() { int pos = 0; var columns = VisibleColumns.ToList(); for (int i = 0; i < columns.Count; i++) { columns[i].Left = pos; pos += columns[i].Width.Value; columns[i].Right = pos; } DoChangeCallback(); }
private void InitializeEditors() { var skip = ViewContext.HttpContext.Items["$SelfInitialize$"] != null && (bool)ViewContext.HttpContext.Items["$SelfInitialize$"] == true; var popupSlashes = new Regex("(?<=data-val-regex-pattern=\")([^\"]*)", RegexOptions.Multiline); ViewContext.HttpContext.Items["$SelfInitialize$"] = true; var dataItem = Editable.DefaultDataItem(); var htmlHelper = new GridHtmlHelper <T>(ViewContext, DataKeyStore); if (Editable.Mode != GridEditMode.InLine && Editable.Mode != GridEditMode.InCell) { var container = new HtmlElement("div").AddClass(UIPrimitives.Grid.InFormContainer); htmlHelper.EditorForModel(dataItem, Editable.TemplateName, Columns.OfType <IGridForeignKeyColumn>().Select(c => c.SerializeSelectList), Editable.AdditionalViewData).AppendTo(container); EditorHtml = popupSlashes.Replace(container.InnerHtml, match => { return(match.Groups[0].Value.Replace("\\", IsInClientTemplate ? "\\\\\\\\" : "\\\\")); }); } else { var cellBuilderFactory = new GridCellBuilderFactory(); VisibleColumns.Each(column => { var cellBuilder = cellBuilderFactory.CreateEditCellBuilder(column, htmlHelper); var editor = cellBuilder.CreateCell(dataItem); var editorHtml = editor.InnerHtml; if (IsInClientTemplate) { editorHtml = popupSlashes.Replace(editorHtml, match => { return(match.Groups[0].Value.Replace("\\", "\\\\")); }); } column.EditorHtml = editorHtml; }); } if (!skip) { ViewContext.HttpContext.Items.Remove("$SelfInitialize$"); } }
private void DoSelectionBG(PaintEventArgs e, List <RollColumn> visibleColumns) { // SuuperW: This allows user to see other colors in selected frames. Color rowColor = Color.White; int _lastVisibleRow = LastVisibleRow; int lastRow = -1; foreach (Cell cell in SelectedItems) { if (cell.RowIndex > _lastVisibleRow || cell.RowIndex < FirstVisibleRow || !VisibleColumns.Contains(cell.Column)) { continue; } Cell relativeCell = new Cell { RowIndex = cell.RowIndex - FirstVisibleRow, Column = cell.Column, }; relativeCell.RowIndex -= CountLagFramesAbsolute(relativeCell.RowIndex.Value); if (QueryRowBkColor != null && lastRow != cell.RowIndex.Value) { QueryRowBkColor(cell.RowIndex.Value, ref rowColor); lastRow = cell.RowIndex.Value; } Color cellColor = rowColor; QueryItemBkColor(cell.RowIndex.Value, cell.Column, ref cellColor); // Alpha layering for cell before selection float alpha = (float)cellColor.A / 255; if (cellColor.A != 255 && cellColor.A != 0) { cellColor = Color.FromArgb(rowColor.R - (int)((rowColor.R - cellColor.R) * alpha), rowColor.G - (int)((rowColor.G - cellColor.G) * alpha), rowColor.B - (int)((rowColor.B - cellColor.B) * alpha)); } // Alpha layering for selection alpha = 0.33f; cellColor = Color.FromArgb(cellColor.R - (int)((cellColor.R - SystemColors.Highlight.R) * alpha), cellColor.G - (int)((cellColor.G - SystemColors.Highlight.G) * alpha), cellColor.B - (int)((cellColor.B - SystemColors.Highlight.B) * alpha)); DrawCellBG(cellColor, relativeCell, visibleColumns); } }
private void DoSelectionBG(List<RollColumn> visibleColumns, Rectangle rect) { Color rowColor = Color.White; var visibleRows = FirstVisibleRow.RangeTo(LastVisibleRow); int lastRow = -1; foreach (Cell cell in _selectedItems) { if (!cell.RowIndex.HasValue || !visibleRows.Contains(cell.RowIndex.Value) || !VisibleColumns.Contains(cell.Column)) { continue; } Cell relativeCell = new Cell { RowIndex = cell.RowIndex - visibleRows.Start, Column = cell.Column, }; relativeCell.RowIndex -= CountLagFramesAbsolute(relativeCell.RowIndex.Value); if (QueryRowBkColor != null && lastRow != cell.RowIndex.Value) { QueryRowBkColor(cell.RowIndex.Value, ref rowColor); lastRow = cell.RowIndex.Value; } Color cellColor = rowColor; QueryItemBkColor?.Invoke(cell.RowIndex.Value, cell.Column, ref cellColor); // Alpha layering for cell before selection float alpha = (float)cellColor.A / 255; if (cellColor.A != 255 && cellColor.A != 0) { cellColor = Color.FromArgb(rowColor.R - (int)((rowColor.R - cellColor.R) * alpha), rowColor.G - (int)((rowColor.G - cellColor.G) * alpha), rowColor.B - (int)((rowColor.B - cellColor.B) * alpha)); } // Alpha layering for selection alpha = 0.33f; cellColor = Color.FromArgb(cellColor.R - (int)((cellColor.R - SystemColors.Highlight.R) * alpha), cellColor.G - (int)((cellColor.G - SystemColors.Highlight.G) * alpha), cellColor.B - (int)((cellColor.B - SystemColors.Highlight.B) * alpha)); DrawCellBG(cellColor, relativeCell, visibleColumns, rect); } }
protected string PutQuery(NameValueCollection queryString) { string result = "UPDATE "; if (!string.IsNullOrEmpty(CatalogName)) { result += CatalogName + "."; } result += Name + " SET"; string predicat = " WHERE 1=1"; foreach (string name in queryString) { if (!FilterableColumns.Any() || FilterableColumns.Contains(name)) { if (Criteria.TryParse(queryString[name], out Criteria criteria)) { predicat += " AND " + criteria.toSqlWhereClause(name); } else { predicat += " AND " + name; if (queryString[name].Contains("%")) { predicat += " LIKE '" + queryString[name] + "'"; } else { predicat += "=" + queryString[name].ToSqlValue(); } } } else { if (!VisibleColumns.Any() || VisibleColumns.Contains(name)) { result += name + "=" + queryString[name].ToSqlValue() + ", "; } } } result += string.Join(", ", DefaultColumns.Select(c => c.Key + "=" + c.Value.ToSqlValue())) + predicat; return(result); }
private GridRenderingData CreateRenderingData() { var renderingData = new GridRenderingData { TableHtmlAttributes = TableHtmlAttributes, DataKeyStore = DataKeyStore, HtmlHelper = new GridHtmlHelper <T>(ViewContext, DataKeyStore), UrlBuilder = UrlBuilder, DataSource = DataProcessor.ProcessedDataSource, Columns = VisibleColumns.Cast <IGridColumn>(), GroupMembers = DataProcessor.GroupDescriptors.Select(g => g.Member), Mode = CurrentItemMode, EditMode = Editing.Mode, HasDetailView = HasDetailView, Colspan = Colspan - Columns.Count(column => column.Hidden), DetailViewTemplate = MapDetailViewTemplate(HasDetailView ? DetailView.Template : null), NoRecordsTemplate = FormatNoRecordsTemplate(), Localization = Localization, ScrollingHeight = Scrolling.Height, EditFormHtmlAttributes = Editing.FormHtmlAttributes, ShowFooter = Footer && VisibleColumns.Any(c => c.FooterTemplate.HasValue() || c.ClientFooterTemplate.HasValue()), AggregateResults = DataProcessor.AggregatesResults, Aggregates = Aggregates.SelectMany(aggregate => aggregate.Aggregates), GroupsCount = DataProcessor.GroupDescriptors.Count, ShowGroupFooter = Aggregates.Any() && VisibleColumns.OfType <IGridBoundColumn>().Any(c => c.GroupFooterTemplate.HasValue()), PopUpContainer = new HtmlFragment(), #if MVC2 || MVC3 CreateNewDataItem = () => Editing.DefaultDataItem(), InsertRowPosition = Editing.InsertRowPosition, EditTemplateName = Editing.TemplateName, AdditionalViewData = Editing.AdditionalViewData, FormId = ViewContext.FormContext.FormId, #endif Callback = RowActionCallback }; if (RowTemplate.HasValue()) { renderingData.RowTemplate = (dataItem, container) => RowTemplate.Apply((T)dataItem, container); } return(renderingData); }
protected override void OnViewChange() { base.OnViewChange(); _inLabelEdit = false; availableFieldsTreeColumns.RootColumn = ViewInfo.ParentColumn; availableFieldsTreeColumns.ShowAdvancedFields = ViewEditor.ShowHiddenFields; availableFieldsTreeColumns.SublistId = ViewInfo.SublistId; availableFieldsTreeColumns.CheckedColumns = ListColumnsInView(); ListViewHelper.ReplaceItems(listViewColumns, VisibleColumns.Select(MakeListViewColumnItem).ToArray()); if (null != SelectedPaths) { var selectedIndexes = VisibleColumns .Select((col, index) => new KeyValuePair<DisplayColumn, int>(col, index)) .Where(kvp => SelectedPaths.Contains(kvp.Key.PropertyPath)) .Select(kvp => kvp.Value); ListViewHelper.SelectIndexes(listViewColumns, selectedIndexes); } UpdateButtons(); }
protected string PostQuery(NameValueCollection queryString) { string result = "INSERT INTO "; if (!string.IsNullOrEmpty(CatalogName)) { result += CatalogName + "."; } result += Name + " ("; string values = " VALUES ("; foreach (string name in queryString) { if (!VisibleColumns.Any() || VisibleColumns.Contains(name)) { result += name + ", "; values += queryString[name].ToSqlValue() + ", "; } } result += string.Join(", ", DefaultColumns.Keys) + ")" + values + string.Join(", ", DefaultColumns.Select(c => c.Value.ToSqlValue())) + ")"; return(result); }
public List <PropertyInfo> GetColumns() { if (_columns == null) { var allColumns = typeof(T).GetProperties() .Where(p => !ColumnsConfig.ColumnsToIgnore.Contains(p.Name)).ToList(); if (VisibleColumns.Any()) { var invalidColumns = VisibleColumns.Where(v => !allColumns.Select(c => c.Name).Contains(v)); if (invalidColumns.Any()) { throw new InvalidColumnNameException(invalidColumns.ToDelimitedString()); } } var orderedColumns = VisibleColumns.Select(visibleColumn => allColumns.FirstOrDefault(c => c.Name == visibleColumn)).ToList(); orderedColumns.AddRange(allColumns.Where(c => !c.IsVirtual() && !orderedColumns.Contains(c))); _columns = new List <PropertyInfo>(); _columns.AddRange(orderedColumns); } return(_columns); }
/// <summary> /// Returns the set of columns that should be checked in the Available Fields Tree. /// </summary> private IEnumerable<PropertyPath> ListColumnsInView() { return VisibleColumns.Select(dc => dc.PropertyPath); }
public void MoveCursorRelative(int x, int y) { LogController("MoveCursorRelative(x:" + x.ToString() + ",y:" + y.ToString() + ",vis:[" + VisibleColumns.ToString() + "," + VisibleRows.ToString() + "]" + ")"); CursorState.CurrentColumn += x; if (CursorState.CurrentColumn < 0) { CursorState.CurrentColumn = 0; } if (CursorState.CurrentColumn >= Columns) { CursorState.CurrentColumn = Columns - 1; } CursorState.CurrentRow += y; if (CursorState.CurrentRow < CursorState.ScrollTop) { CursorState.CurrentRow = CursorState.ScrollTop; } var scrollBottom = (CursorState.ScrollBottom == -1) ? Rows - 1 : CursorState.ScrollBottom; if (CursorState.CurrentRow > scrollBottom) { CursorState.CurrentRow = scrollBottom; } ChangeCount++; }
private void PaintInternal(ConsoleBitmap context) { if (this.Height < 5) { context.DrawString("Grid can't render in a space this small", 0, 0); return; } if (VisibleColumns.Count == 0) { context.DrawString(NoVisibleColumnsMessage.ToConsoleString(DefaultColors.H1Color), 0, 0); return; } List <ConsoleString> headers = new List <ConsoleString>(); List <List <ConsoleString> > rows = new List <List <ConsoleString> >(); List <ColumnOverflowBehavior> overflowBehaviors = new List <ColumnOverflowBehavior>(); if (VisibleColumns.Where(c => c.WidthPercentage != 0).Count() == 0) { foreach (var col in VisibleColumns) { col.WidthPercentage = 1.0 / VisibleColumns.Count; } } foreach (var header in VisibleColumns) { headers.Add(header.ColumnDisplayName); var colWidth = (int)(header.WidthPercentage * this.Width); if (header.OverflowBehavior is SmartWrapOverflowBehavior) { (header.OverflowBehavior as SmartWrapOverflowBehavior).MaxWidthBeforeWrapping = colWidth; } else if (header.OverflowBehavior is TruncateOverflowBehavior) { (header.OverflowBehavior as TruncateOverflowBehavior).ColumnWidth = (header.OverflowBehavior as TruncateOverflowBehavior).ColumnWidth == 0 ? colWidth : (header.OverflowBehavior as TruncateOverflowBehavior).ColumnWidth; } overflowBehaviors.Add(header.OverflowBehavior); } int viewIndex = visibleRowOffset; foreach (var item in DataView.Items) { List <ConsoleString> row = new List <ConsoleString>(); int columnIndex = 0; foreach (var col in VisibleColumns) { var value = PropertyResolver(item, col.ColumnName.ToString()); var displayValue = value == null ? "<null>".ToConsoleString() : (value is ConsoleString ? (ConsoleString)value : value.ToString().ToConsoleString()); if (viewIndex == SelectedIndex && this.CanFocus) { if (this.SelectionMode == GridSelectionMode.Row || (this.SelectionMode == GridSelectionMode.Cell && columnIndex == selectedColumnIndex)) { displayValue = new ConsoleString(displayValue.ToString(), this.Background, HasFocus ? DefaultColors.FocusColor : DefaultColors.SelectedUnfocusedColor); } } row.Add(displayValue); columnIndex++; } viewIndex++; rows.Add(row); } ConsoleTableBuilder builder = new ConsoleTableBuilder(); ConsoleString table; table = builder.FormatAsTable(headers, rows, RowPrefix.ToString(), overflowBehaviors, Gutter); if (FilterText != null) { table = table.Highlight(FilterText, DefaultColors.HighlightContrastColor, DefaultColors.HighlightColor, StringComparison.InvariantCultureIgnoreCase); } if (DataView.IsViewComplete == false) { table += "Loading more rows...".ToConsoleString(DefaultColors.H1Color); } else if (DataView.IsViewEndOfData && DataView.Items.Count == 0) { table += NoDataMessage.ToConsoleString(DefaultColors.H1Color); } else if (DataView.IsViewEndOfData) { if (ShowEndIfComplete) { table += EndOfDataMessage.ToConsoleString(DefaultColors.H1Color); } } else { table += MoreDataMessage; } context.DrawString(table, 0, 0); if (FilteringEnabled) { } }
public override void WriteInitializationScript(TextWriter writer) { var options = new Dictionary <string, object>(Events); var autoBind = DataSource.Type != DataSourceType.Server && AutoBind.GetValueOrDefault(true); var columns = VisibleColumns.Select(c => c.ToJson()); var idPrefix = "#"; if (IsInClientTemplate) { idPrefix = "\\" + idPrefix; } if (columns.Any()) { options["columns"] = columns; } if (Grouping.Enabled) { options["groupable"] = Grouping.ToJson(); } if (Pageable.Enabled) { Pageable.AutoBind = autoBind; options["pageable"] = Pageable.ToJson(); } if (Sortable.Enabled) { var sorting = Sortable.ToJson(); options["sortable"] = sorting.Any() ? (object)sorting : true; } if (Selectable.Enabled) { options["selectable"] = String.Format("{0}, {1}", Selectable.Mode, Selectable.Type); } if (Filterable.Enabled) { var filtering = Filterable.ToJson(); options["filterable"] = filtering.Any() ? (object)filtering : true; } if (ColumnMenu.Enabled) { var menu = ColumnMenu.ToJson(); options["columnMenu"] = menu.Any() ? (object)menu : true; } if (Resizable.Enabled) { options["resizable"] = true; } if (ColumnResizeHandleWidth != defaultColumnResizeHandleWidth) { options["columnResizeHandleWidth"] = ColumnResizeHandleWidth; } if (Reorderable.Enabled) { options["reorderable"] = true; } if (!Scrollable.Enabled) { options["scrollable"] = false; } else { var scrolling = Scrollable.ToJson(); if (scrolling.Any()) { options["scrollable"] = scrolling; } } if (Editable.Enabled) { options["editable"] = Editable.ToJson(); } if (ToolBar.Enabled) { options["toolbar"] = ToolBar.ToJson(); } if (autoBind == false) { options["autoBind"] = autoBind; } options["dataSource"] = DataSource.ToJson(); if (!String.IsNullOrEmpty(ClientDetailTemplateId)) { options["detailTemplate"] = new ClientHandlerDescriptor { HandlerName = String.Format("kendo.template($('{0}{1}').html())", idPrefix, ClientDetailTemplateId) }; } if (!String.IsNullOrEmpty(ClientRowTemplate)) { options["rowTemplate"] = ClientRowTemplate; } if (!String.IsNullOrEmpty(ClientAltRowTemplate)) { options["altRowTemplate"] = ClientAltRowTemplate; } if (Navigatable.Enabled) { options["navigatable"] = true; } if (Mobile != MobileMode.Disabled) { if (Mobile == MobileMode.Auto) { options["mobile"] = true; } else { options["mobile"] = Mobile.ToString().ToLowerInvariant(); } } writer.Write(Initializer.Initialize(Selector, "Grid", options)); base.WriteInitializationScript(writer); }
/// <summary> /// Displays or hides columns based on VisibleColumns property. /// </summary> private void DisplayColumns() { string[] visibleColumns = VisibleColumns.Split('|'); // Hide all first foreach (var item in gridElem.NamedColumns.Values) { item.Visible = false; } // Show columns that should be visible foreach (var item in visibleColumns) { string key = null; switch (item) { case COLUMN_NUMBER: key = "Number"; break; case COLUMN_PRICE: key = "Price"; break; case COLUMN_DEPARTMENT: key = "Department"; break; case COLUMN_MANUFACTURER: key = "Manufacturer"; break; case COLUMN_SUPPLIER: key = "Supplier"; break; case COLUMN_PUBLIC_STATUS: key = "PublicStatus"; break; case COLUMN_INTERNAL_STATUS: key = "InternalStatus"; break; case COLUMN_REORDER_AT: key = "ReorderAt"; break; case COLUMN_AVAILABLE_ITEMS: key = "AvailableItems"; break; case COLUMN_ITEMS_TO_BE_REORDERED: key = "ItemsToBeReordered"; break; case COLUMN_ALLOW_FOR_SALE: key = "AllowForSale"; break; } // Show column if (key != null) { gridElem.NamedColumns[key].Visible = true; } } // Show option category column if not only product listed if (ProductType != PRODUCT_TYPE_PRODUCTS) { gridElem.NamedColumns["OptionCategory"].Visible = true; } // If global products are allowed, display column if (ECommerceSettings.AllowGlobalProducts(CMSContext.CurrentSiteName)) { gridElem.NamedColumns["Global"].Visible = true; } }