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

kb(grid): Update CheckBox KB after customer feedback #2074

Merged
merged 5 commits into from Apr 29, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 30 additions & 16 deletions knowledge-base/grid-checkbox-editing.md
Expand Up @@ -26,17 +26,14 @@ res_type: kb

## Description

To edit a checkbox in a Grid cell, users need to click once to put the row (or cell) in edit mode. They they need another click to change the checkbox value. How to do this with only one click?
This KB article answers the following questions:

How to update boolean values in the Grid with no edit mode?

How to toggle checkboxes in the Grid directly without using the built-in editing feature?

The Grid is not editable, but it should allow users to check and uncheck check box values.

How to use a single click on Grid checkboxes to set the opposite value?

How to get a checkbox value in the Grid for update action on button click?
* To edit a checkbox in a Grid cell, users need to click once to put the row (or cell) in edit mode. They they need another click to change the checkbox value. How to do this with only one click?
dimodi marked this conversation as resolved.
Show resolved Hide resolved
* How to update boolean values in the Grid with no edit mode?
* How to toggle checkboxes in the Grid directly without using the built-in editing feature?
* The Grid is not editable, but it should allow users to check and uncheck check box values.
dimodi marked this conversation as resolved.
Show resolved Hide resolved
dimodi marked this conversation as resolved.
Show resolved Hide resolved
* How to use a single click on Grid checkboxes to set the opposite value?
dimodi marked this conversation as resolved.
Show resolved Hide resolved
dimodi marked this conversation as resolved.
Show resolved Hide resolved
* How to get a checkbox value in the Grid for update action on button click?
dimodi marked this conversation as resolved.
Show resolved Hide resolved

## Solution

Expand All @@ -51,7 +48,11 @@ How to get a checkbox value in the Grid for update action on button click?
<TelerikGrid OnRead="@OnGridRead"
TItem="@User"
EditMode="@GridEditMode.Incell"
OnUpdate="@OnGridUpdate">
OnUpdate="@OnGridUpdate"
OnCreate="@OnGridCreate">
<GridToolBarTemplate>
<GridCommandButton Command="Add">Add</GridCommandButton>
</GridToolBarTemplate>
<GridColumns>
<GridColumn Field="@nameof(User.Name)" />
<GridColumn Field="@nameof(User.Admin)" Title="No Template" />
Expand All @@ -78,7 +79,9 @@ How to get a checkbox value in the Grid for update action on button click?
</TelerikGrid>

@code {
private List<User> Users { get; set; }
private List<User> Users { get; set; } = new();

private int LastId { get; set; }

private async Task OnAdminValueChanged(bool newValue, User user)
{
Expand Down Expand Up @@ -125,6 +128,17 @@ How to get a checkbox value in the Grid for update action on button click?
}
}

private async Task OnGridCreate(GridCommandEventArgs args)
{
// simulate network delay
await Task.Delay(100);

var user = (User)args.Item;
user.Id = ++LastId;

Users.Insert(0, user);
}

private async Task OnGridRead(GridReadEventArgs args)
{
// simulate network delay
Expand All @@ -144,9 +158,9 @@ How to get a checkbox value in the Grid for update action on button click?
{
Users.Add(new User()
{
Id = i,
Name = "User Name " + i,
Admin = i % 2 == 0
Id = ++LastId,
Name = "User Name " + LastId,
Admin = LastId % 2 == 0
});
}

Expand All @@ -156,7 +170,7 @@ How to get a checkbox value in the Grid for update action on button click?
public class User
{
public int Id { get; set; }
public string Name { get; set; }
public string Name { get; set; } = string.Empty;
public bool Admin { get; set; }
}
}
Expand Down