Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set selected items in grid view when using the grid to edit data #957

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

MarkKamberger
Copy link

Setup the grid using SetSelected

 <Grid @ref="levelGrid" TItem="Level"
   Class="table table-hover table-bordered marginBottom1"
   Data="_levels"
   AllowFiltering="true"
   AllowSelection="true"
   FixedHeader="true"
   Height="300"
   Unit="Unit.Px"
   SelectionMode="GridSelectionMode.Multiple"
   SelectedItemsChanged="OnSelectedItemsChanged"
   SetSelected="setSelected"
   Responsive="true">

 <GridColumns>
     <GridColumn TItem="Level" HeaderText="Additional Levels" PropertyName="Description">
         @context.Description
     </GridColumn>
 </GridColumns>
 </Grid>

Code:

 HashSet<Level> setSelected = [];

 protected override async Task<Task> OnParametersSetAsync()
 {
      Input = new InputModel
      {
           Description = _course.Description,
           Selectedlevels = _course.AdditionalLevels.Select(x => x.Level).ToHashSet()
      };
      setSelected = _course.AdditionalLevels.Select(x => x.Level).ToHashSet();
     return base.OnParametersSetAsync();
 }
  private Task OnSelectedItemsChanged(HashSet<Level> levels)
  {
       Input.Selectedlevels = levels;
       setSelected = Input.Selectedlevels;
       return Task.CompletedTask;
  }
 private sealed class InputModel
 {
     [Required]
     [Display(Name = "Description")]
     public string Description { get; set; }

     [Required]
     [MinLength(1)]
     public HashSet<Level> Selectedlevels { get; set; }
 }

@MarkKamberger MarkKamberger changed the title Set selected items in gid view when using the grid to edit data Set selected items in grid view when using the grid to edit data Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant