Dynamically hiding a column from a WebGrid

0

How can I hide a WebGrid column at run time ? For example, I want to hide the Parametro column, it would look like this:

    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: Hiding a column from a WebGrid shows how hide but not at runtime.

    
asked by anonymous 14.06.2017 / 20:23

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()));
    
15.06.2017 / 15:56