Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1459
Grid not visible - I must be missing something basic...
posted

I'm just trying out my first data grid, and am hitting a problem. Everything appears to run okay, but at the end I have a page with no grid visible. I'm doubtless missing something obvious, but despite routing through the demos I'm not finding it. Below are my startup code and the component I'm working on - I'm using server side blazor, by the way:

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc(options => options.EnableEndpointRouting = false).SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_3_0);
            services.AddRazorPages();
            services.AddScoped<IClaimsTransformation, ClaimsTransformer>();
            services.AddScoped<ICustomerService, CustomerService>();
            services.AddScoped<IMeterService, MeterService>();
            services.AddScoped<ITariffService, TariffService>();
            services.AddScoped<IContractService, ContractService>();
            services.AddScoped<IAdminService, AdminService>();
            services.AddScoped<IReadingsService, ReadingsService>();
            services.AddDbContext<Model>(options =>
                options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")), ServiceLifetime.Transient);

            services.AddIgniteUIBlazor(typeof(DataGridModule));
            services.AddBlazoredToast();
            services.AddServerSideBlazor();
            services.AddSingleton(Configuration.GetSection("AppConfig").Get<AppConfig>());

            services.AddAuthentication(Microsoft.AspNetCore.Server.IISIntegration.IISDefaults.AuthenticationScheme);
            services.AddAuthorization();
        }

@page "/readinglists"

<AuthorizeView Context="secCont">
    <Authorized>
        <h3>Reading Lists</h3>

            <DataGrid Height="100%" Width="100%"
                      @ref="GridLists"
                      DataSource="Data"
                      AutoGenerateColumns="false"
                      GroupHeaderDisplayMode="DataSourceSectionHeaderDisplayMode.Combined" >
                <TextColumn Field="Area" HeaderText="Area" Width="250" />
                <TextColumn Field="ListLabel"  HeaderText="Period"></TextColumn>
                <DateTimeColumn Field="ReadingDate" HeaderText="Reading Date"/>
               
            </DataGrid>
    </Authorized>
    <NotAuthorized>
        <PageRestricted></PageRestricted>
    </NotAuthorized>
</AuthorizeView>
@code {

    private DataGrid gridLists;
    private DataGrid GridLists {
        get=>gridLists;
        set {
            gridLists = value;
            OnGridCreated();
            StateHasChanged();
        }
    }

    private void OnGridCreated() {
        var loc = new ColumnGroupDescription { Field = "Location", DisplayName = "Location" };
        GridLists.GroupDescriptions.Add(loc);
    }

}

namespace Utilities.Pages.Readings {
    public partial class ReadingLists {
        [Inject] 
        public IIgniteUIBlazor IgniteUIBlazor { get; set; }
        [Inject]
        public IReadingsService ReadingsService { get; set; }

        private IEnumerable<ReadingListSummaryData> Data { get; set; } = new List<ReadingListSummaryData>();


        protected override async Task OnInitializedAsync() {
            try {
                DataGridModule.Register(IgniteUIBlazor);
                GridColumnOptionsModule.Register(IgniteUIBlazor);
                Data = new List<ReadingListSummaryData>() {
                    new ReadingListSummaryData() {Area="Birkenhead", Frequency=BillingFrequency.Monthly, ReadingDate=DateTime.Today.AddDays(6) },
                    new ReadingListSummaryData() {Area="Birkenhead", Frequency=BillingFrequency.Monthly, ReadingDate=DateTime.Today.AddDays(-24) },
                    new ReadingListSummaryData() {Area="Birkenhead", Frequency=BillingFrequency.Quarterly, ReadingDate=DateTime.Today.AddDays(16) },
                    new ReadingListSummaryData() {Area="Central", Frequency=BillingFrequency.Monthly, ReadingDate=DateTime.Today.AddDays(-6) },
                    new ReadingListSummaryData() {Area="City Lofts", Frequency=BillingFrequency.Monthly, ReadingDate=DateTime.Today.AddDays(-14) },
                    new ReadingListSummaryData() {Area="City Lofts", Frequency=BillingFrequency.Quarterly, ReadingDate=DateTime.Today.AddDays(-52) }
                };

                Ready = true;
                await Task.CompletedTask;
            } catch (Exception ex) {
                ErrorText = $"Problem fetching reading list data: {ex.Message}";
            }
        }
    }
}

Parents Reply Children
No Data