Skip to content

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

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

Closed
wants to merge 4 commits into 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
gvreddy04 added a commit that referenced this pull request Jan 5, 2025
@gvreddy04
Copy link
Contributor

@MarkKamberger Will be fixed in Grid selected items #992

@gvreddy04 gvreddy04 closed this Jan 5, 2025
@gvreddy04 gvreddy04 added this to the 3.3.0 milestone Jan 5, 2025
@gvreddy04 gvreddy04 added enhancement New feature or request area-grid labels Jan 5, 2025
gvreddy04 added a commit that referenced this pull request Jan 15, 2025
* #298, #593, and #957 - grid selected items
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-grid enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants