Skip to content

Commit

Permalink
BatchEdit | Ongoing
Browse files Browse the repository at this point in the history
  • Loading branch information
David-Moreira committed Oct 31, 2023
1 parent 4b1398c commit 691b5cb
Show file tree
Hide file tree
Showing 14 changed files with 1,713 additions and 1,295 deletions.
3 changes: 3 additions & 0 deletions Demos/Blazorise.Demo/Components/SideMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@
Editing
</BarDropdownToggle>
<BarDropdownMenu>
<BarDropdownItem To="tests/datagrid/editing/batch-editing">
Batch Editing
</BarDropdownItem>
<BarDropdownItem To="tests/datagrid/editing/button-row">
Button Row
</BarDropdownItem>
Expand Down
69 changes: 69 additions & 0 deletions Demos/Blazorise.Demo/Pages/Tests/DataGrid/EditingBatchEdit.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
@page "/tests/datagrid/editing/batch-editing"
<Row>
<Column>
<Card Margin="Margin.Is4.OnY">
<CardHeader>
<CardTitle>Datagrid: Batch Editing</CardTitle>
</CardHeader>
<CardBody>
<Paragraph>
Allows you to batch edit by allowing the user to edit multiple rows and then save all the changes at once.
</Paragraph>

</CardBody>
<CardBody>
<DataGrid TItem="Employee"
Data="inMemoryData"
Responsive
ShowPager
ShowPageSizes
@bind-SelectedRow="@selectedEmployee"
Editable
EditMode="@DataGridEditMode.Inline"
BatchEdit
UseValidation
ValidationsSummaryLabel="The following validation errors have occurred..."
ShowValidationsSummary>
<DataGridColumns>
<DataGridCommandColumn />
<DataGridColumn TextAlignment="TextAlignment.Center" TItem="Employee" Field="@nameof( Employee.Id )" Caption="#" Width="60px" />
<DataGridColumn TItem="Employee" Field="@nameof( Employee.FirstName )" Caption="First Name" Editable />
<DataGridColumn TItem="Employee" Field="@nameof( Employee.LastName )" Caption="Last Name" Editable />
<DataGridColumn TItem="Employee" Field="@nameof( Employee.Email )" Caption="Email" Editable />
<DataGridColumn TItem="Employee" Field="@nameof( Employee.City )" Caption="City" Editable>
<CaptionTemplate>
<Icon Name="IconName.City" /> @context.Caption
</CaptionTemplate>
</DataGridColumn>
<DataGridColumn TItem="Employee" Field="@nameof( Employee.Zip )" Caption="Zip">
</DataGridColumn>
<DataGridDateColumn TItem="Employee" Field="@nameof( Employee.DateOfBirth )" DisplayFormat="{0:dd.MM.yyyy}" Caption="Date Of Birth" Editable />
<DataGridNumericColumn TItem="Employee" Field="@nameof( Employee.Childrens )" Caption="Childrens" Editable Filterable="false" />
<DataGridSelectColumn TItem="Employee" Field="@nameof( Employee.Gender )" Caption="Gender" Editable Data="EmployeeData.Genders" ValueField="(x) => ((Gender)x).Code" TextField="(x) => ((Gender)x).Description" />
<DataGridColumn TItem="Employee" Field="@nameof( Employee.Salary )" Caption="Salary" Editable Width="140px" DisplayFormat="{0:C}" DisplayFormatProvider="@System.Globalization.CultureInfo.GetCultureInfo("fr-FR")" TextAlignment="TextAlignment.End">
</DataGridColumn>
<DataGridCheckColumn TItem="Employee" Field="@nameof(Employee.IsActive)" Caption="Active" Editable Filterable="false">
<DisplayTemplate>
<Check TValue="bool" Checked="context.IsActive" Disabled ReadOnly />
</DisplayTemplate>
</DataGridCheckColumn>
</DataGridColumns>
</DataGrid>
</CardBody>
</Card>
</Column>
</Row>

@code {

[Inject] EmployeeData EmployeeData { get; set; }

private List<Employee> inMemoryData;
private Employee selectedEmployee;

protected override async Task OnInitializedAsync()
{
inMemoryData = ( await EmployeeData.GetDataAsync().ConfigureAwait( false ) ).Take( 25 ).ToList();
await base.OnInitializedAsync();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
private bool showCommandColumn = true;
private List<Employee> inMemoryData;
private Employee selectedEmployee;
private DataGridEditMode editMode = DataGridEditMode.Form;

protected override async Task OnInitializedAsync()
{
Expand Down
29 changes: 24 additions & 5 deletions Source/Extensions/Blazorise.DataGrid/Contexts/CellEditContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,22 @@ namespace Blazorise.DataGrid;
/// </summary>
public class CellEditContext
{
protected object cellValue;

/// <summary>
/// Gets or sets the editor value.
/// </summary>
public object CellValue { get; set; }
public object CellValue
{
get => cellValue;
set
{
cellValue = value;
Modified = true;
}
}

public bool Modified { get; private set; }
}

/// <summary>
Expand All @@ -35,13 +47,15 @@ public class CellEditContext<TItem> : CellEditContext
/// Initializes a new instance of the <see cref="CellEditContext{TItem}"/>.
/// </summary>
/// <param name="item">An item to which this cell belongs.</param>
/// <param name="cellValue">The initial cell value</param>
/// <param name="setCellValue">Method that will be called when cell is manually updated.</param>
/// <param name="getCellValue">Method that will be called when cell value is manually read.</param>
public CellEditContext( TItem item, Action<string, object> setCellValue, Func<string, object> getCellValue )
public CellEditContext( TItem item, object cellValue, Action<string, object> setCellValue, Func<string, object> getCellValue )
{
Item = item;
SetCellValue = setCellValue;
GetCellValue = getCellValue;
this.Item = item;
this.cellValue = cellValue;
this.SetCellValue = setCellValue;
this.GetCellValue = getCellValue;
}

/// <summary>
Expand Down Expand Up @@ -73,4 +87,9 @@ public object ReadCell( string fieldName )
{
return GetCellValue?.Invoke( fieldName );
}

internal void SetCellValueInternal( object cellValue )
{
CellValue = cellValue;
}
}
Loading

0 comments on commit 691b5cb

Please sign in to comment.