protected object GetReferencedValue <T>(MGrid <T> pGrid, IMGridColumn column, Type pPropertyType, string pReferencedId) { var propInfo = column.GetType().GetProperty(nameof(MGridComplexPropertyColumn <object, object> .ReferencedValues)); var referencedValues = propInfo.GetValue(column) as IEnumerable; var enumerator = referencedValues.GetEnumerator(); if (!enumerator.MoveNext()) { return(null); } var firstValue = enumerator.Current; var pi = pGrid.GetIdentifierProperty(firstValue); //no idict support right now var refIdValue = ReflectionHelper.ChangeType(pReferencedId, pi.PropertyType); var queryable = referencedValues.AsQueryable(); var param = Expression.Parameter(pPropertyType, "p"); var property = Expression.Property(param, pi.Name); var exprEqual = Expression.Equal(property, Expression.Constant(refIdValue)); var lambda = Expression.Lambda(exprEqual, param); var method = FirstOrDefaultMethod.MakeGenericMethod(new[] { pPropertyType }); var val = method.Invoke(null, new object[] { queryable, lambda }); return(val); }
private void AddMFormField(RenderTreeBuilder pBuilder, IMGridColumn pColumn, bool pIsInFilterRow, double pLeftOffset, BoundingBox pBoundingBox) { if (pColumn is IMGridPropertyColumn pc) { var propertyType = mPropertyInfoCache[pc].PropertyType; if (pIsInFilterRow) { propertyType = GetNullableTypeIfNeeded(propertyType); } var method = typeof(MGrid <T>).GetMethod(nameof(MGrid <T> .AddPropertyField), BindingFlags.Instance | BindingFlags.NonPublic).MakeGenericMethod(propertyType); method.Invoke(this, new object[] { pBuilder, pColumn, pc, pIsInFilterRow, pLeftOffset, pBoundingBox }); // AddPropertyField(builder3, column, pc, propertyType); } else if (pColumn is IMGridEditFieldGenerator <T> fieldGenerator) { AddFieldGenerator(pBuilder, fieldGenerator, pIsInFilterRow, pLeftOffset, pBoundingBox); } else { pBuilder.OpenComponent <MField>(5); pBuilder.CloseComponent(); } }
internal static object GetComparer(this IMGridColumn pColumn) { object comparer = null; if (pColumn is IMGridCustomComparer) { comparer = ((dynamic)pColumn).Comparer; } return(comparer); }
private void AddPropertyField <TProperty>(RenderTreeBuilder pBuilder, IMGridColumn pColumn, IMGridPropertyColumn pPropertyColumn, bool pIsInFilterRow, double pLeftOffset, BoundingBox pBoundingBox) { var attributes = mPropertyInfoCache[pPropertyColumn].GetAttributes()?.ToList() ?? new List <Attribute>(); if (pIsInFilterRow) { if (!pColumn.EnableFilter && !attributes.OfType <ReadOnlyAttribute>().Any()) { attributes.Add(new ReadOnlyAttribute()); } if (pColumn.EnableFilter && attributes.Any(a => a is ReadOnlyAttribute)) { attributes = attributes.Where(a => !(a is ReadOnlyAttribute)).ToList(); } } if (pColumn is IMGridComplexEditableColumn <TProperty> complex) { if (pIsInFilterRow) { pBuilder.OpenComponent <MComplexPropertyField <ExpandoObject, TProperty> >(5); } else { pBuilder.OpenComponent <MComplexPropertyField <T, TProperty> >(5); } pBuilder.AddAttribute(776, "Property", pPropertyColumn.Property); pBuilder.AddAttribute(777, "PropertyType", typeof(TProperty)); pBuilder.AddAttribute(778, "Attributes", attributes.ToArray()); if (complex.FormTemplate != null && !pIsInFilterRow || (pIsInFilterRow && pColumn.EnableFilter)) { pBuilder.AddAttribute(781, "Template", complex.FormTemplate); } pBuilder.AddStyleWithAttribute(784, Extensions.MFORM_IN_TABLE_ROW_TD_STYLE_ATTRIBUTE, pLeftOffset, pBoundingBox); pBuilder.CloseComponent(); } else { pBuilder.OpenComponent <MField>(790); pBuilder.AddAttribute(792, "Property", pPropertyColumn.Property); pBuilder.AddAttribute(793, "PropertyType", typeof(TProperty)); pBuilder.AddAttribute(794, "Attributes", attributes.ToArray()); pBuilder.AddStyleWithAttribute(976, Extensions.MFORM_IN_TABLE_ROW_TD_STYLE_ATTRIBUTE, pLeftOffset, pBoundingBox); pBuilder.CloseComponent(); } }
public void RegisterColumn(IMGridColumn pColumn) { if (ColumnsList.Any(c => c.Identifier == pColumn.Identifier)) { return; } ColumnsList.Add(pColumn); if (pColumn is MGridActionColumn <T> ) { mHasActionColumn = true; } if (pColumn is IMGridPropertyColumn propc) { var iprop = ReflectionHelper.GetIMPropertyInfo(typeof(T), propc.Property, propc.PropertyType); propc.PropertyType = iprop.PropertyType; if (propc.Attributes != null) { iprop.SetAttributes(propc.Attributes); } mPropertyInfoCache.Add(propc, iprop); if (pColumn is IMGridSortableColumn sc && sc.SortDirection != MSortDirection.None) { object comparer = null; if (pColumn is IMGridCustomComparer) { comparer = ((dynamic)pColumn).Comparer; } SortInstructions.Add(new SortInstruction() { Direction = sc.SortDirection, PropertyInfo = iprop, Index = sc.SortIndex, Comparer = comparer }); } } mFilterModel = null; ClearDataCache(); StateHasChanged(); }
private static object GetReferencedValue(IMGridColumn column, Type pPropertyType, Guid pReferencedId) { var propInfo = column.GetType().GetProperty(nameof(MGridComplexPropertyColumn <object, object> .ReferencedValues)); var referencedValues = propInfo.GetValue(column) as IEnumerable; var queryable = referencedValues.AsQueryable(); var param = Expression.Parameter(pPropertyType, "p"); var property = Expression.Property(param, "Id"); var exprEqual = Expression.Equal(property, Expression.Constant(pReferencedId)); var lambda = Expression.Lambda(exprEqual, param); var method = FirstOrDefaultMethod.MakeGenericMethod(new[] { pPropertyType }); var val = method.Invoke(null, new object[] { queryable, lambda }); return(val); }
public virtual void AppendToTableRowData(RenderTreeBuilder pBuilder, IMGridColumn pColumn, T pRow) { }
private void AddInlineFormFields(RenderTreeBuilder pBuilder, IMGridColumn[] pVisibleColumns, bool pIsFilterRow) { double left = 0; for (int i = 0; i < pVisibleColumns.Length; i++) { IMGridColumn column = pVisibleColumns[i]; var columnWidth = GetColumnWidth(i); var bWidth = columnWidth; var bHeight = mFieldBoundingBox.Height; if (mFieldBoundingBox.BorderCollapse == "separate") { bWidth -= mFieldBoundingBox.BorderRight; } else if (mFieldBoundingBox.BorderCollapse == "collapse") { if (i == 0) { bWidth -= mFieldBoundingBox.BorderRight / 2; } else { bWidth -= mFieldBoundingBox.BorderRight; } if (i == 0 || i == pVisibleColumns.Length - 1) { bWidth -= mTableBorderLeft / 2; } } BoundingBox box = new BoundingBox() { BorderTop = 0, BorderRight = mFieldBoundingBox.BorderRight, BorderSpace = mFieldBoundingBox.BorderSpace, BorderCollapse = mFieldBoundingBox.BorderCollapse, Width = bWidth, Height = bHeight, }; AddMFormField(pBuilder, column, pIsFilterRow, left, box); if (mFieldBoundingBox.BorderCollapse == "separate") { left += columnWidth + mFieldBoundingBox.BorderSpace; } else if (mFieldBoundingBox.BorderCollapse == "collapse") { if (i == 0) { left += columnWidth + mFieldBoundingBox.BorderRight / 2 + mFieldBoundingBox.BorderSpace; left -= mTableBorderLeft / 2; } else { left += columnWidth + mFieldBoundingBox.BorderSpace; } } else { throw new InvalidOperationException($"border-collapse {mFieldBoundingBox.BorderCollapse} not supported!"); } } }
private void AddContentRow(RenderTreeBuilder pBuilder, T pEntry, MGridAction pAction) { Guid entryId = GetId(pEntry); bool rowEdit = EditRow.HasValue && EditRow.Value == entryId; pBuilder.AddMarkupContent(503, "\r\n"); pBuilder.OpenElement(504, "tr"); string cssClass = "m-grid-row"; if (rowEdit) { cssClass += " m-grid-edit-row"; } bool selected = Selected.HasValue && Selected == entryId; if (selected) { cssClass += " m-grid-highlight"; } Formatter.AppendToTableRow(pBuilder, ref cssClass, pEntry, selected); pBuilder.AddAttribute(519, "class", cssClass); pBuilder.AddAttribute(522, "onclick", EventCallback.Factory.Create <MouseEventArgs>(this, (a) => { OnRowClick(pEntry, a); })); pBuilder.AddEventStopPropagationAttribute(527, "onclick", true); pBuilder.AddAttribute(530, "ondblclick", EventCallback.Factory.Create <MouseEventArgs>(this, async(a) => { await StartEditRow(pEntry, a); })); if (rowEdit) { EditValue = pEntry; AddEditRow(pBuilder, pAction, false, EditValue); } else { for (int i = 0; i < ColumnsList.Count; i++) { IMGridColumn column = ColumnsList[i]; if (!column.ShouldRenderColumn) { continue; } pBuilder.OpenElement(550, "td"); Formatter.AppendToTableRowData(pBuilder, column, pEntry); if (column is IMGridColumnGenerator <T> generator) { pBuilder.AddContent(556, generator.GenerateContent(pEntry)); } else if (column is IMGridPropertyColumn pc) { var iprop = mPropertyInfoCache[pc]; pBuilder.AddContent(561, Formatter.FormatPropertyColumnValue(pc, iprop, pEntry)); } pBuilder.CloseElement(); //td } } pBuilder.CloseElement(); //tr }
protected override void BuildRenderTree(RenderTreeBuilder builder) { base.BuildRenderTree(builder); builder.OpenRegion(this.GetHashCode()); if (this.ChildContent != null) { RenderFragment child() => (builder2) => { builder2.AddContent(56, this.ChildContent); }; builder.OpenComponent <CascadingValue <MGrid <T> > >(4); builder.AddAttribute(207, "Value", this); builder.AddAttribute(208, "ChildContent", child()); builder.CloseComponent(); } RenderFragment childMain() => (builder2) => { builder2.OpenElement(216, "div"); builder2.AddAttribute(217, "class", "m-grid-container"); builder2.AddMultipleAttributes(218, AdditionalAttributes); builder2.OpenElement(221, "div"); builder2.AddAttribute(222, "class", "m-btn-toolbar"); builder2.AddAttribute(223, "role", "toolbar"); if (ToolbarItems != ToolbarItem.None) { builder2.OpenElement(227, "div"); builder2.AddAttribute(228, "class", "m-btn-group mr-2"); builder2.AddAttribute(229, "role", "group"); if (EnableAdding && ToolbarItems.HasFlag(ToolbarItem.Add)) { builder2.OpenElement(233, "button"); builder2.AddAttribute(234, "class", "m-btn m-btn-primary"); builder2.AddAttribute(235, "onclick", EventCallback.Factory.Create <MouseEventArgs>(this, OnToolbarAdd)); builder2.AddContent(236, (MarkupString)$"<i class=\"fa fa-plus\"></i> {L["Add"]}"); builder2.CloseElement(); // button } if (EnableEditing && ToolbarItems.HasFlag(ToolbarItem.Edit)) { builder2.OpenElement(242, "button"); builder2.AddAttribute(243, "class", "m-btn m-btn-primary"); builder2.AddAttribute(244, "onclick", EventCallback.Factory.Create <MouseEventArgs>(this, OnToolbarEdit)); builder2.AddContent(245, (MarkupString)$"<i class=\"fa fa-edit\"></i> {L["Edit"]}"); builder2.CloseElement(); // button } if (EnableDeleting && ToolbarItems.HasFlag(ToolbarItem.Delete)) { builder2.OpenElement(251, "button"); builder2.AddAttribute(252, "class", "m-btn m-btn-primary"); builder2.AddAttribute(253, "onclick", EventCallback.Factory.Create <MouseEventArgs>(this, OnToolbarRemove)); builder2.AddContent(254, (MarkupString)$"<i class=\"fa fa-trash-alt\"></i> {L["Delete"]}"); builder2.CloseElement(); // button } builder2.CloseElement(); // div } if (EnableFilterRow) { builder2.OpenElement(263, "button"); builder2.AddAttribute(264, "class", "m-btn m-btn-primary m-btn-sm"); builder2.AddAttribute(265, "onclick", EventCallback.Factory.Create <MouseEventArgs>(this, OnToggleFilter)); builder2.OpenElement(266, "i"); builder2.AddAttribute(267, "class", "fas fa-filter"); builder2.CloseElement(); //i builder2.AddContent(269, L["Filter"]); builder2.CloseElement(); //button } builder2.CloseElement(); // div builder2.OpenElement(277, "table"); if (HtmlTableClass != null) { builder2.AddAttribute(282, "class", HtmlTableClass + (EnableEditing ? " m-clickable" : string.Empty) + (IsEditingRow ? " m-editing" : string.Empty)); } else { builder2.AddAttribute(286, "class", "m-grid m-grid-striped m-grid-bordered m-grid-hover" + (EnableEditing ? " m-clickable" : string.Empty) + (IsEditingRow ? " m-editing" : string.Empty)); } if (FixedColumns) { builder2.AddAttribute(291, "style", "table-layout: fixed;"); } builder2.AddElementReferenceCapture(294, (__value) => { mTableReference = __value; }); builder2.OpenElement(299, "thead"); builder2.OpenElement(300, "tr"); for (int i = 0; i < ColumnsList.Count; i++) { IMGridColumn column = ColumnsList[i]; if (!column.ShouldRenderColumn) { continue; } builder2.OpenElement(309, "th"); builder2.AddAttribute(310, "data-identifier", column.Identifier); builder2.AddMultipleAttributes(311, column.AdditionalAttributes); if (FixedColumns) { var width = GetColumnWidth(i); builder2.AddAttribute(315, "style", $"width: {width.ToString(CultureInfo.InvariantCulture)}px"); } builder2.AddAttribute(318, "onclick", EventCallback.Factory.Create <MouseEventArgs>(this, (a) => OnColumnHeaderClick(column, a))); builder2.AddAttribute(319, "scope", "col"); builder2.AddContent(321, (MarkupString)column.HeaderText); if (EnableUserSorting) { var sortInstr = SortInstructions.FirstOrDefault(si => si.PropertyInfo.GetFullName() == column.Identifier); if (sortInstr != null) { if (sortInstr.Direction == MSortDirection.Ascending) { builder2.AddContent(329, (MarkupString)"<i class=\"fa fa-arrow-down m-grid-header-icon\"></i>"); } if (sortInstr.Direction == MSortDirection.Descending) { builder2.AddContent(332, (MarkupString)"<i class=\"fa fa-arrow-up m-grid-header-icon\"></i>"); } } } builder2.CloseElement(); //th } builder2.CloseElement(); //tr builder2.CloseElement(); //thead builder2.AddMarkupContent(342, "\r\n"); builder2.OpenElement(434, "tbody"); if (DataCache == null) { if (DataSource != null) { DataCache = GetIQueryable(DataSource as IQueryable <T>).ToArray(); } else if (DataAdapter == null) { throw new InvalidOperationException("Please provide a " + nameof(DataSource) + " or " + nameof(DataAdapter)); } } if (IsFilterRowVisible) { AddFilterRow(builder2); } if (DataCache != null) { foreach (var entry in DataCache) { AddContentRow(builder2, entry, MGridAction.Edit); } } if (NewValue != null) { AddContentRow(builder2, NewValue, MGridAction.Add); } builder2.AddMarkupContent(24, "\r\n"); builder2.CloseElement(); //tbody builder2.CloseElement(); // table builder2.AddMarkupContent(391, "\r\n"); if (Pager != null) { int pagecount = (int)Math.Ceiling(DataCountCache / (double)Pager.PageSize); builder2.OpenComponent <MPager>(11); builder2.AddAttribute(398, "CurrentPage", Pager.CurrentPage); builder2.AddAttribute(399, "PageCount", pagecount); builder2.AddAttribute(400, "OnPageChanged", EventCallback.Factory.Create <int>(this, OnPagerPageChanged)); builder2.AddAttribute(402, "ChildContent", (RenderFragment)((builder3) => { builder3.AddMarkupContent(404, "\r\n\r\n "); builder3.OpenElement(405, "div"); builder3.AddAttribute(406, "class", "m-pagination-entry m-pagination-tools"); builder3.AddMarkupContent(407, "\r\n "); if (Pager.SelectablePageSizes != null) { builder3.OpenElement(411, "select"); builder3.AddAttribute(412, "class", "m-form-control"); builder3.AddAttribute(413, "onchange", EventCallback.Factory.Create <ChangeEventArgs>(this, OnPageSizeChange)); foreach (var entry in Pager.SelectablePageSizes) { builder3.OpenElement(418, "option"); builder3.AddAttribute(419, "value", entry); builder3.AddContent(420, entry); builder3.CloseElement(); } builder3.AddMarkupContent(424, "\r\n"); builder3.CloseElement(); //select } builder3.AddMarkupContent(428, "\r\n"); builder3.AddMarkupContent(429, $"<span class=\"m-pagination-descr\">{string.Format(L["{0} entries of {1}"], DataCache?.Count, TotalDataCountCache)}</span>"); if (EnableExport) { builder3.OpenElement(435, "button"); builder3.AddAttribute(436, "class", "m-btn m-btn-secondary m-btn-icon m-btn-sm"); builder3.AddAttribute(437, "onclick", EventCallback.Factory.Create <MouseEventArgs>(this, OnExportClicked)); builder3.AddContent(438, (MarkupString)"<i class=\"fas fa-download\"></i>"); builder3.CloseElement(); // button } builder3.CloseElement(); //div } )); builder2.CloseComponent(); } builder2.CloseElement(); //div }; builder.AddContent(453, childMain()); builder.CloseRegion(); }