I want to conditionally render a icon in a button inside the <GridCommandColumns> , here is an example of what I want to achieve:
<GridColumn HeaderText="Gerenciar" AutoFit="true">
<GridCommandColumns>
@{
var ctx = (context as CidadesViewModel);
if (ctx.IsLocked)
{
// Button with an locked lock icon
}
else
{
// Button with an unlocked lock icon
}
}
<GridCommandColumn Type="CommandButtonType.Edit" ID="EditarCidade" ButtonOption="@(new CommandButtonOptions() {IconCss="e-icons e-edit", CssClass="e-flat" })"></GridCommandColumn>
<GridCommandColumn Type="CommandButtonType.Save" ID="SalvarCidade" ButtonOption="@(new CommandButtonOptions() {IconCss="e-icons e-save", CssClass="e-flat" })"></GridCommandColumn>
<GridCommandColumn Type="CommandButtonType.Cancel" ID="Cancelar" ButtonOption="@(new CommandButtonOptions() {IconCss="e-icons e-cancel-icon", CssClass="e-flat" })"></GridCommandColumn>
</GridCommandColumns>
</GridColumn>
Is it possible?
OBS: I saw this example but it is not sufficient for me since I need to access the context and specific button when rendering and not only the "Args.Row" property.
In Addition, I dont want to rewrite it to use the column
Thanks Vignesh.
I tried it by my self and ended up rewriting my application to use sfButtons and Column Template as you suggested, so, no needing to write an solution example.
Although, I think it would be very useful to access context data inside <GridCommandColumns>. It is possible to consider it to an future update of the Grid component?
<GridEvents RowDataBound="RowDataBoundHandler" TValue="Order"></GridEvents>
...
<GridCommandColumns>
<GridCommandColumn ButtonOption="@(new CommandButtonOptions() { CssClass = "e-icons e-lockunlock" })"></GridCommandColumn>
...
</GridCommandColumns>
<style>
.e-lockiconset .e-rowcell.e-unboundcell .e-unboundcelldiv .e-lockunlock::before {
content: '\e735';
}
.e-unlockiconset .e-rowcell.e-unboundcell .e-unboundcelldiv .e-lockunlock::before {
content: '\e197';
}
</style>
public void RowDataBoundHandler(RowDataBoundEventArgs<Order> Args)
{
if (Args.Data.IsLocked)
{
Args.Row.AddClass(new string[] { "e-lockiconset" });
}
else if (!Args.Data.IsLocked)
{
Args.Row.AddClass(new string[] { "e-unlockiconset" });
}
}
|