BlazorTable icon indicating copy to clipboard operation
BlazorTable copied to clipboard

Table of integers [Bug]

Open KevinBurton opened this issue 4 years ago • 0 comments
trafficstars

I am trying to build a table of integers but that is not working. The column headers never show up.

ProjectsTable

Looking at the Chrome Debugger I see that a Null reference exception is thrown but I have not be able to determine where

ProjectsTableException1 ProjectsTableException2

I have a very simple table

@using BlazorTable
<h2>Projects</h2>
<Table TableItem="int" DataLoader="_loader" Items="data" PageSize="5" SelectionType="selectionType" RowClickAction="RowClick" SelectedItems="selectedItems" ShowSearchBar="false">
    <Column TableItem="int" Title="Project Id" Field="@(x => x)" Sortable="true" Width="10%" DefaultSortColumn="true" />
    <Pager ShowPageNumber="true" ShowTotalCount="true" />
</Table>

with the code behind

using BlazorTable;
using BlazorTable.Components.ServerSide;
using BlazorTable.Interfaces;
using BreakpointManagement.Services;
using Microsoft.AspNetCore.Components;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace BreakpointManagement.ComponentLibrary
{
    public partial class ProjectPicker
    {
        [Inject]
        private IBreakpointManagementDataService dataService { get; set; }

        private IDataLoader<int> _loader;

        private IEnumerable<int> data;

        private int selected;

        private SelectionType selectionType = SelectionType.Single;

        private List<int> selectedItems = new List<int>();

        protected override async Task OnInitializedAsync()
        {
            _loader = new ProjectDataLoader(dataService);
            data = (await _loader.LoadDataAsync(null)).Records;
        }
        public void RowClick(int data)
        {
            selected = data;
            StateHasChanged();
        }
    }

    public class ProjectDataLoader : IDataLoader<int>
    {
        private readonly IBreakpointManagementDataService _dataService;
        public ProjectDataLoader(IBreakpointManagementDataService dataService)
        {
            _dataService = dataService;
        }
        public async Task<PaginationResult<int>> LoadDataAsync(FilterData parameters)
        {
            if (parameters == null) return new PaginationResult<int>();
            IList<int> results;
            if (parameters == null)
            {
                results = await _dataService.GetBreakpointProjects();
            }
            else if (parameters.Top == null)
            {
                results = await _dataService.GetBreakpointProjects();
            }
            else if (string.IsNullOrWhiteSpace(parameters.OrderBy))
            {
                results = await _dataService.GetBreakpointProjects(parameters.Top.Value, parameters.Skip.Value);
            }
            else
            {
                var order = parameters.OrderBy.Split(" ");
                if (order.Length >= 2)
                {
                    results = await _dataService.GetBreakpointProjects(parameters.Top.Value, parameters.Skip.Value, order[0]);
                }
                else
                {
                    results = await _dataService.GetBreakpointProjects(parameters.Top.Value, parameters.Skip.Value);
                }
            }
            var count = await _dataService.GetBreakpointProjectCount();
            return new PaginationResult<int>
            {
                Records = results,
                Skip = parameters?.Skip ?? 0,
                Total = int.Parse(count),
                Top = parameters?.Top ?? 0
            };
        }
    }
}

Expected behavior I expect a table to be displayed with one column.

KevinBurton avatar Mar 08 '21 14:03 KevinBurton