using AyCode.Core.Loggers; using DevExpress.Blazor; using DevExpress.Data.Helpers; using DevExpress.Utils.Filtering.Internal; using FruitBankHybrid.Shared.Services.SignalRs; using Microsoft.AspNetCore.Components; using System.Reflection; namespace FruitBankHybrid.Shared.Components; public class MgGridBase : DxGrid { private bool _isFirstInitializeParameterCore; private bool _isFirstInitializeParameters; [Inject] public required IEnumerable LogWriters { get; set; } [Inject] public required FruitBankSignalRClient FruitBankSignalRClient { get; set; } [Parameter] public bool IsMasterGrid { get; set; } = false; [Parameter] public required object DataSource { get => Data; set => Data = value; } protected void OnCustomizeElement(GridCustomizeElementEventArgs e) { //if (!IsMasterGrid) e.CssClass = "hideDetailButton"; if (IsMasterGrid && e.ElementType == GridElementType.DataRow && e.VisibleIndex % 2 == 1 && !e.Grid.IsRowSelected(e.VisibleIndex) && !e.Grid.IsRowFocused(e.VisibleIndex)) { e.CssClass = " alt-item"; } if(e.ElementType == GridElementType.HeaderCell) { e.Style = "background-color: #E6E6E6;"; //e.CssClass = "header-bold"; } } protected override Task SetParametersAsyncCore(ParameterView parameters) { if (!_isFirstInitializeParameterCore) { //if (typeof(TDataItem) is IId || typeof(TDataItem) is IId) KeyFieldName = "Id"; //base.DataItemDeleting = EventCallback.Factory.Create(this, OnItemDeleting); //base.EditModelSaving = EventCallback.Factory.Create(this, OnItemSaving); CustomizeElement += OnCustomizeElement; _isFirstInitializeParameterCore = true; } return base.SetParametersAsyncCore(parameters); } protected override void OnParametersSet() { if (!_isFirstInitializeParameters) { ShowGroupPanel = IsMasterGrid; ShowSearchBox = IsMasterGrid; ShowFilterRow = IsMasterGrid; FilterMenuButtonDisplayMode=(IsMasterGrid ? GridFilterMenuButtonDisplayMode.Never : GridFilterMenuButtonDisplayMode.Always); DetailRowDisplayMode = IsMasterGrid ? GridDetailRowDisplayMode.Auto : GridDetailRowDisplayMode.Never; DetailExpandButtonDisplayMode = IsMasterGrid ? GridDetailExpandButtonDisplayMode.Auto : GridDetailExpandButtonDisplayMode.Never; TextWrapEnabled = false; AllowSelectRowByClick = true; HighlightRowOnHover = true; AutoCollapseDetailRow = true; AutoExpandAllGroupRows = false; PagerVisible = IsMasterGrid; PageSize = IsMasterGrid ? 15 : 50; AllowColumnReorder = true; AllowGroup = IsMasterGrid; AllowSort = true; FocusedRowEnabled = true; ColumnResizeMode = GridColumnResizeMode.ColumnsContainer; EditMode = GridEditMode.EditRow; //VirtualScrollingEnabled = IsMasterGrid; PageSizeSelectorVisible = true; _isFirstInitializeParameters = true; } base.OnParametersSet(); } //public RenderFragment AddCommandColumn() //{ // RenderFragment columns = b => // { // if (!IsMasterGrid) // { // b.OpenComponent(0, typeof(DxGridCommandColumn)); // b.CloseComponent(); // } // }; // this.Columns.ApplyChain(x) = AddCommandColumn(); // return columns; //} //private RenderFragment BuildColumnsGrid() //{ // PropertyInfo[] props = DataSource.FirstOrDefault().GetType().GetProperties(); // RenderFragment columns = b => // { // foreach (var prop in props) // { // if (prop.PropertyType == typeof(string)) // { // b.OpenComponent(0, typeof(DxGridDataColumn)); // b.AddAttribute(0, "FieldName", prop.Name); // b.CloseComponent(); // } // } // }; // return columns; //} }