I have a checkbox in a grid (Telerik Grid for Blazor). When I click the checkbox (using incell editing) the value changes however it does not save to the database and if I leave the page and come back the data is back to the old values.
This is the code for the grid:
<TelerikGrid Class="custom-icons" Data="@OfficesList"
Reorderable = "true"
EditMode = "@GridEditMode.Incell"
Sortable = "true"
Pageable = "true"
SelectionMode = "GridSelectionMode.Multiple"
OnUpdate = "@UpdateItem"
@ref="OfficeListGrid"
@bind-SelectedItems="@SelectedItems">
<DetailTemplate Context="office">
<Incumbents Office="@office"></Incumbents>
</DetailTemplate>
<GridColumns>
<GridCommandColumn Context="OfficeCommandsContext">
<GridCommandButton Command="Edit" Class="btn btn-sm btn-primary" Icon="edit">Edit</GridCommandButton>
</GridCommandColumn>
<GridColumn Field="@nameof(GetOfficesResult.OfficeName)" Title="Office" Editable="false"/>
<GridColumn Field="@nameof(GetOfficesResult.OfficeSeqNum)" Title="Office Sequence #"Editable="false" />
<GridColumn Field="@nameof(GetOfficesResult.IsVacant)" Title="Is Vacant" Editable="false"/>
<GridColumn Field="@nameof(GetOfficesResult.IsPrimaryPartisan)" Title="Is Primary Partisan" Editable="false" />
<GridColumn Field="@nameof(GetOfficesResult.IsPrimaryNonPartisan)" Title="Is Primary Non Partisan" Editable="false" />
<GridColumn Field="@nameof(GetOfficesResult.PrimaryDistrictType)" Title="Primary Voting District Type" Editable="false" />
<GridColumn Field="@nameof(GetOfficesResult.PrimaryDistrictCode)" Title="Primary Voting District" Editable="false" />
<GridColumn Field="@nameof(GetOfficesResult.IsGeneral)" Title="Is General Ballot" Editable="false" />
<GridColumn Field="@nameof(GetOfficesResult.GeneralDistrictType)" Title="General Voting District Type" Editable="false" />
<GridColumn Field="@nameof(GetOfficesResult.GeneralDistrictCode)" Title="General Voting District" Editable="false" />
<GridColumn Field="@nameof(GetOfficesResult.CanFileAgain)" Title="Can File Again?" Editable="false"/>
<GridColumn Field="@nameof(GetOfficesResult.TermLength)" Title="Term Length" Editable="false"/>
<GridColumn Field="@nameof(GetOfficesResult.FilingDistrictType)" Title="General Voting District Type" Editable="false"/>
<GridColumn Field="@nameof(GetOfficesResult.FilingDistrictCode)" Title="General Voting District" Editable="false"/>
<GridColumn Field="@nameof(GetOfficesResult.SalaryType)" Title="Salary Type" Editable="false"/>
<GridColumn Field="@nameof(GetOfficesResult.Salary)" Title="Salary" Editable="false"/>
<GridColumn Field="@nameof(GetOfficesResult.FilingFee)" Title="Filing Fee" Editable="false"/>
<GridColumn Field="@nameof(GetOfficesResult.NextElection)" Title="Next Election" Editable="false"/>
<GridColumn Field="@nameof(GetOfficesResult.Notes)" Title="Notes" Editable="false"/>
<GridColumn Field="@nameof(GetOfficesResult.FederalOnly)" Title="Is Federal Only" />
</GridColumns>
</TelerikGrid>
This is the code behind for the Update Item:
public async Task UpdateItem(GridCommandEventArgs args)
{
var currState = OfficeListGrid.GetState();
GetOfficesResult offices = (GetOfficesResult)args.Item;
////Reset any current editing
currState.EditField = null;
currState.OriginalEditItem = null;
//Reset any current insertion
currState.InsertedItem = null;
//Add the item to edit to the state
var target = OfficesList.FirstOrDefault(o => o.OfficeID == offices.OfficeID);
if (target != null)
{
target.OfficeID = offices.OfficeID;
target.OfficeName = offices.OfficeName;
target.FilingDistrictCode = offices.FilingDistrictCode;
target.FilingDistrictType = offices.FilingDistrictType;
target.PrimaryDistrictCode = offices.PrimaryDistrictCode;
target.PrimaryDistrictType = offices.PrimaryDistrictType;
target.GeneralDistrictCode = offices.GeneralDistrictCode;
target.GeneralDistrictType = offices.GeneralDistrictType;
target.IsVacant = offices.IsVacant;
target.IsPrimaryPartisan = offices.IsPrimaryPartisan;
target.IsPrimaryNonPartisan = offices.IsPrimaryNonPartisan;
target.IsGeneral = offices.IsGeneral;
target.OfficeSeqNum = offices.OfficeSeqNum;
target.CanFileAgain = offices.CanFileAgain;
target.TermLength = offices.TermLength;
target.SalaryType = offices.SalaryType;
target.Salary = offices.Salary;
target.FilingFee = offices.FilingFee;
target.NextElection = offices.NextElection;
target.Notes = offices.Notes;
target.FederalOnly = offices.FederalOnly;
}
offices = args.Item as GetOfficesResult;
GetOfficesResult originalItem = OfficesList.Where(itm => itm.OfficeID == offices.OfficeID).FirstOrDefault();
GetOfficesResult itemToEdit = GetOfficesResult.GetClonedInstance(originalItem);
await OfficeListGrid.SetState(currState);
SelectedItems = OfficesList;
AddToSelectedCollection(itemToEdit);
//Use the state to remove the edited item and close the editor
//currState.EditField = null;
//currState.OriginalEditItem = null;
await OfficeListGrid.SetState(currState);
await RebindGrid();
}
I am not sure why it doesn't save
Thank you in advance
Max