mirror of
https://github.com/radzenhq/radzen-blazor.git
synced 2026-07-08 18:16:08 +00:00
- Edited value cells now repaint: fire the changed cell's notification even inside a command batch (only dependent recalc is deferred to EndUpdate). - Table sort excludes the header (and totals) row by sorting DataBodyRange; the cell-menu and context-menu sorts are now table/auto-filter aware. - Re-apply active filters after a sort (and on sort undo) so filtered-out rows stay hidden by value. - Enable Merge, Borders, Conditional and Data Validation tools when a range is selected by subscribing to Selection.Changed. - Keep the worksheet prefix on cross-sheet references in the formula-bar syntax highlighter (use the raw token text). Adds regression tests for all of the above.
85 lines
3.2 KiB
Plaintext
85 lines
3.2 KiB
Plaintext
@namespace Radzen.Blazor
|
|
@using Radzen.Blazor
|
|
@using Radzen.Blazor.Spreadsheet
|
|
@using Radzen.Blazor.Spreadsheet.Tools
|
|
@using Radzen.Documents.Spreadsheet
|
|
@inject DialogService DialogService
|
|
@implements IDisposable
|
|
|
|
<RadzenSplitButton Click=@OnClickAsync Icon="format_color_fill" Text=@(Spreadsheet?.Localize(nameof(RadzenStrings.Spreadsheet_Conditional)) ?? "Conditional") Disabled=@IsDisabled Variant="Variant.Outlined" ButtonStyle="ButtonStyle.Base" Size="ButtonSize.Small">
|
|
<ChildContent>
|
|
<RadzenSplitButtonItem Text=@(Spreadsheet?.Localize(nameof(RadzenStrings.Spreadsheet_GreaterThanMenu)) ?? "Greater Than...") Value="greater" />
|
|
<RadzenSplitButtonItem Text=@(Spreadsheet?.Localize(nameof(RadzenStrings.Spreadsheet_LessThanMenu)) ?? "Less Than...") Value="less" />
|
|
<RadzenSplitButtonItem Text=@(Spreadsheet?.Localize(nameof(RadzenStrings.Spreadsheet_BetweenMenu)) ?? "Between...") Value="between" />
|
|
<RadzenSplitButtonItem Text=@(Spreadsheet?.Localize(nameof(RadzenStrings.Spreadsheet_EqualToMenu)) ?? "Equal To...") Value="equal" />
|
|
<RadzenSplitButtonItem Text=@(Spreadsheet?.Localize(nameof(RadzenStrings.Spreadsheet_TextContainsMenu)) ?? "Text Contains...") Value="text" />
|
|
</ChildContent>
|
|
</RadzenSplitButton>
|
|
|
|
@code {
|
|
#nullable enable
|
|
|
|
[CascadingParameter]
|
|
public Worksheet? Worksheet { get; set; }
|
|
|
|
[CascadingParameter]
|
|
public ISpreadsheet? Spreadsheet { get; set; }
|
|
|
|
private bool IsDisabled
|
|
=> Worksheet?.Selection.Cell == CellRef.Invalid
|
|
|| Spreadsheet?.IsFeatureAllowed(SpreadsheetFeature.ConditionalFormatting) == false;
|
|
|
|
private readonly EventBinding<Selection> selectionBinding;
|
|
|
|
public RadzenSpreadsheetConditionalFormat()
|
|
{
|
|
selectionBinding = new EventBinding<Selection>(
|
|
s => s.Changed += OnSelectionChanged,
|
|
s => s.Changed -= OnSelectionChanged);
|
|
}
|
|
|
|
protected override void OnParametersSet()
|
|
{
|
|
selectionBinding.Bind(Worksheet?.Selection);
|
|
}
|
|
|
|
private void OnSelectionChanged()
|
|
{
|
|
StateHasChanged();
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
selectionBinding.Dispose();
|
|
}
|
|
|
|
private async Task OnClickAsync(RadzenSplitButtonItem? item)
|
|
{
|
|
if (Worksheet is null || Worksheet.Selection.Cell == CellRef.Invalid)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var ruleType = item?.Value switch
|
|
{
|
|
"less" => ConditionalFormatRuleType.LessThan,
|
|
"between" => ConditionalFormatRuleType.Between,
|
|
"equal" => ConditionalFormatRuleType.EqualTo,
|
|
"text" => ConditionalFormatRuleType.TextContains,
|
|
_ => ConditionalFormatRuleType.GreaterThan
|
|
};
|
|
|
|
var result = await DialogService.OpenAsync<ConditionalFormatDialog>(Spreadsheet?.Localize(nameof(RadzenStrings.Spreadsheet_ConditionalFormattingTitle)) ?? "Conditional Formatting",
|
|
new Dictionary<string, object?>
|
|
{
|
|
{ "RuleType", ruleType }
|
|
});
|
|
|
|
if (result is ConditionalFormatBase rule && Spreadsheet is not null)
|
|
{
|
|
var command = new ConditionalFormatCommand(Worksheet, Worksheet.Selection.Range, rule);
|
|
await Spreadsheet.ExecuteAsync(command);
|
|
}
|
|
}
|
|
}
|