I was not able to set the hidden flag of div in the Dialog Template under the Grid Adding / Editing
@page "/comtest"
@using System;
@using Syncfusion.Blazor.Cards
@using ValidationRules = Syncfusion.Blazor.Grids.ValidationRules;
<div id="commMethod" class='configuration-container'>
<header>
<div class="module-title">
<div class='title'>COMMUNICATION</div>
<div class='underline'></div>
</div>
</header>
<br />
<div class="col-lg-12 control-section">
<div class="content-wrapper">
<div class="row">
<SfGrid DataSource="@_testList" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" })" AllowPaging="true">
<GridEditSettings AllowAdding="true" AllowDeleting="true" AllowEditing="true" Mode="EditMode.Dialog" Dialog="DialogParams">
<Template>
@{ var sType = (context as TestDTO); }
<div class="form-row">
<div class="form-group col-md-6">
<SfDropDownList ID="SelectedType" TItem="string" @bind-Value="@(sType.MySelectedType)" TValue="string" DataSource="@EnumCommTypeValues" FloatLabelType="FloatLabelType.Always" Placeholder="Type">
<DropDownListEvents TItem="string" TValue="string" ValueChange="@OnTypeChanged"></DropDownListEvents>
</SfDropDownList>
</div>
</div>
<div hidden="@_IsShow"> show ME</div>
</Template>
</GridEditSettings>
<GridColumns>
<GridColumn Field=@nameof(TestDTO.MySelectedType) HeaderText="Type" EditType="EditType.DropDownEdit" ValidationRules="@(new ValidationRules { Required = true })" Width="150"></GridColumn>
</GridColumns>
</SfGrid>
</div>
</div>
</div>
</div>
@code
{
public enum SelectedTypes
{
A,
B
}
public class TestDTO
{
public string MySelectedType { get; set; }
}
private TestDTO[] _testList;
private DialogSettings DialogParams = new DialogSettings { MinHeight = "600px", Width = "450px" };
private bool _IsShow = false;
private IEnumerable<string> EnumCommTypeValues = Enum.GetNames(typeof(SelectedTypes));
public void OnTypeChanged(Syncfusion.Blazor.DropDowns.ChangeEventArgs<string, string> args)
{
if (args.ItemData == SelectedTypes.A.ToString())
{
_IsShow = true;
}
else
{
_IsShow = false;
}
}
}
|
<SfGrid @ref="GridInstance" DataSource="@GridData" Toolbar="@(new string[] {"Add", "Edit" ,"Delete","Update","Cancel" })">
<GridEvents OnActionBegin="ActionBeginHandler" TValue="OrdersDetails"></GridEvents>
<GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="@EditMode.Dialog">
<Template>
@{
var Order = (context as OrdersDetails);
<div>
<div class="form-row">
<div class="form-group col-md-12">
<label class="e-float-text e-label-top">Ship Country</label>
<SfDropDownList ID="ShipCountry" @bind-Value="@(Order.ShipCountry)" TItem="OrdersDetails" TValue="string" DataSource="@GridData">
<DropDownListFieldSettings Value="ShipCountry" Text="ShipCountry"></DropDownListFieldSettings>
<DropDownListEvents TItem="OrdersDetails" TValue="string" ValueChange="@OnTypeChanged"></DropDownListEvents>
</SfDropDownList>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-12">
@if (_IsShow)
{
<div> show ME</div>
}
</div>
</div>
</div>
}
</Template>
</GridEditSettings>
<GridColumns>
<GridColumn Field=@nameof(OrdersDetails.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="@TextAlign.Center" HeaderTextAlign="@TextAlign.Center" Width="140"></GridColumn>
<GridColumn Field=@nameof(OrdersDetails.CustomerID) HeaderText="Customer Name" Width="150"></GridColumn>
<GridColumn Field=@nameof(OrdersDetails.Freight) HeaderText="Freight" Format="C2" Width="140" TextAlign="@TextAlign.Right" HeaderTextAlign="@TextAlign.Right"></GridColumn>
<GridColumn Field=@nameof(OrdersDetails.OrderDate) HeaderText="Order Date" Format="d" Type="ColumnType.Date" Width="160"></GridColumn>
<GridColumn Field=@nameof(OrdersDetails.ShipCountry) HeaderText="Ship Country" Width="150"></GridColumn>
</GridColumns>
</SfGrid>
@code{
SfGrid<OrdersDetails> GridInstance { get; set; }
private bool _IsShow = false;
//to show te text based on the record while editing (when particualr column has value already)
public void ActionBeginHandler(ActionEventArgs<OrdersDetails> Args)
{
//will be triggered before record goes into edit mode
if (Args.RequestType == Syncfusion.Blazor.Grids.Action.BeginEdit)
{
if (Args.Data.ShipCountry == "Denmark" || Args.Data.ShipCountry == "Austria")
{
_IsShow = true;
}
else
{
_IsShow = false;
}
}
if (Args.RequestType == Syncfusion.Blazor.Grids.Action.Save || Args.RequestType == Syncfusion.Blazor.Grids.Action.Cancel)
{
_IsShow = false;
}
}
//to show the text while changing the value. useful while inserting a record
public void OnTypeChanged(Syncfusion.Blazor.DropDowns.ChangeEventArgs<string, OrdersDetails> args)
{
if (args.ItemData.ShipCountry == "Denmark" || args.ItemData.ShipCountry == "Austria")
{
_IsShow = true;
}
else
{
_IsShow = false;
}
GridInstance.PreventRender(false);
}
|