1

ASP.NET MVC4 Razor application page contains table. Table first two columns have fixed names. Other columns have variable names created dynamically from pivot table.

Code below renders all columns and created table header with property names.

How to rendel table starting at third column so first two columns are not shown ? How to render table without column headers ?

View:

@inherits ViewBase<ViewModels.CustomerCardViewModel>

@{
var gd = new WebGrid(source: Model.Rows.Skip(1), canPage: false, canSort: false, rowsPerPage: 1000);
}

<!DOCTYPE HTML>
<html>
... head skipped
<body>
        @gd.GetHtml()
    </div>
    <hr />
</body>
</html>

ViewModel:

    public class CustomerCardViewModel : ViewModelBase
    {
        public IEnumerable<dynamic> Rows { get; set; }
...
}

ASP.NET MVC4, Razor, Bootstrap 3, jquery are used.

Andrus
  • 26,339
  • 60
  • 204
  • 378

1 Answers1

1

1.To render a table without column headers:

   @gd.GetHtml(
        displayHeader:false
    )

2.To hide columns - If you have a static list of columns you can use How to hide a column in the Webgrid in aspasp.net MVC? but if it's dynamic then just write a little function using jQuery to hide the desired columns:

$('.table tr').each(function () {
    var tr = $(this);
    var children = tr.children();
    $(children[0]).hide();
    $(children[1]).hide();
});
Community
  • 1
  • 1
Denys Wessels
  • 16,829
  • 14
  • 80
  • 120
  • First two columns have fixed property names. Other property names and their count will vary. I tried `$('td:nth-child(1),th:nth-child(2)').hide()` but columns are still shown. How to hide them ? Maybe new collection without first two columns can freated from IEnumerable or first two columns can deleted or webgrid column list can created dynamically without binding to first two columns? – Andrus Jun 11 '16 at 16:48