Praveen S
Praveen S

Reputation: 650

How to hide a column in the Webgrid in aspasp.net MVC?

I am new to MVC and I use Webgrid to display some customer values. I need to hide columns together with their headers. How do i do this?

CSS: gridhide { visibility:hidden }
Code: grid.Column("Id", "ID", style: "gridhide"),

Upvotes: 4

Views: 21331

Answers (3)

Matthew Lock
Matthew Lock

Reputation: 13556

I ended up using jQuery to hide the column on the client side. Not ideal but easy to implement. Eg to hide the second column:

$('td:nth-child(2),th:nth-child(2)').hide();

Another option would be to simply not add the column to the grid in the first place like so, as seen here: https://forums.asp.net/post/5850519.aspx

var books = db.Query(sql);
var columns = new List<WebGridColumn>();
columns.Add(new WebGridColumn(){ColumnName = "BookId", Header = "Book Id" });
if(books.Any(b =>b.Price != null)){
    columns.Add(new WebGridColumn(){ColumnName = "Price", Header = "Price" });
}
var grid = new WebGrid(books);

Upvotes: 2

Praveen S
Praveen S

Reputation: 650

I hide particular column: Please Try This: WEBGRID

grid.Column(null,null, format: @<input type="hidden" name="IDHidden" value="@item.IDHidden"/>),

Upvotes: 9

Amit
Amit

Reputation: 15387

gridhide is a class, define class instead of style in grid.column

Upvotes: 0

Related Questions