Dynamically hide a Webgrid column

Asked

Viewed 195 times

0

How can I hide at runtime a column from Webgrid ? For example, I want to hide the column Parametro, it would be something like that:

    grid.Column("Empresa", "Empresa"),
if(item.valor1 == X){
    grid.Column("Parametro", "Parametro"),
}
     grid.Column("Data", format: @<text>@item.DataInclusao.ToString("dd/MM/yyyy")</text>),

In this post: Hide a column from a Webgrid shows how to hide but not at runtime.

1 answer

0

I found the solution that worked for my scenario:

var gridColumns = new List<WebGridColumn>();

    if (Model.Empresa != null)
    {
        gridColumns.Add(grid.Column("Empresa", "Empresa"));
    };

   @grid.GetHtml(
tableStyle: "grid",
headerStyle: "head",
columns: grid.Columns(
gridColumns.ToArray()));

Browser other questions tagged

You are not signed in. Login or sign up in order to post.