コード例 #1
0
        private void InitPhotos()
        {
            photoDs = new PhotosDataSource {
                HttpFactory = HttpFactory
            };
            photoOp = new GridOptions
            {
                Datasource             = photoDs,
                EnablePagination       = true,
                PaginationPageSize     = 20,
                SuppressRowDeselection = true,
                RowModelType           = RowModelType.Infinite,
                RowSelection           = RowSelection.Multiple,
                SuppressCellSelection  = true,
                EnableBrowserTooltips  = true
            };
            photoEv = new GridEvents
            {
                SelectionChanged = (Action <RowNode[]>)(nodes =>
                {
                    Console.WriteLine("Photo Selected: " + (nodes?.Length == 0
                        ? "none" : string.Join(",", nodes.Select(n => n.Id))));

                    if ((nodes?.Length ?? 0) == 0)
                    {
                        thumbnails = null;
                    }
                    else
                    {
                        var opts = new System.Text.Json.JsonSerializerOptions
                        {
                            PropertyNameCaseInsensitive = true,
                        };
                        var photos = System.Text.Json.JsonSerializer.Deserialize <Photo[]>(
                            System.Text.Json.JsonSerializer.Serialize(
                                nodes.Select(n => n.Data), opts), opts);
                        thumbnails = photos.Select(p => p.ThumbnailUrl);
                    }
                    StateHasChanged();
                }),
            };
        }
コード例 #2
0
        private async Task InitAlbums()
        {
            albumDs = new AlbumsDataSource {
                HttpFactory = HttpFactory
            };
            albumOp = new GridOptions
            {
                Datasource             = albumDs,
                EnablePagination       = true,
                SuppressRowDeselection = true,
                RowModelType           = RowModelType.Infinite,
                RowSelection           = RowSelection.Multiple,
                SuppressCellSelection  = true,
                ColumnDefinitions      = new[]
                {
                    new ColumnDefinition
                    {
                        HeaderName         = "ID",
                        Field              = "id",
                        IsResizable        = true,
                        IsSortable         = true,
                        CellRenderer       = "funcColorCellRenderer",
                        CellRendererParams = new { color = "red" }
                    },
                    new ColumnDefinition
                    {
                        HeaderName         = "User ID",
                        Field              = "userId",
                        IsResizable        = true,
                        IsSortable         = true,
                        CellRenderer       = "ClassColorCellRenderer",
                        CellRendererParams = new { color = "cyan" }
                    },
                    new ColumnDefinition
                    {
                        HeaderName  = "Title",
                        Field       = "title",
                        IsResizable = true,
                        IsSortable  = true
                    },
                }
            };

            albumEv = new GridEvents
            {
                SelectionChanged = (Action <RowNode[]>)(nodes =>
                {
                    var sel = nodes?.Select(n => n.Id).ToArray();
                    Console.WriteLine("Album Selected: " + string.Join(",", sel));

                    var prevCount = photoDs.AlbumIds?.Length ?? 0;
                    photoDs.AlbumIds = sel;
                    _ = Task.Run(async() =>
                    {
                        try
                        {
                            // This seems to be necessary if the DS produced no
                            // rows previously, otherwise the grid doesn't update
                            if (prevCount == 0)
                            {
                                await photoGrid.Api.SetDatasource();
                            }
                            else
                            {
                                await photoGrid.Api.PurgeInfiniteCache();
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Failed to update DS: " + ex.ToString());
                        }
                    });
                }),
            };

            //var module = await Module;
        }