0

I want to set an ID on each column inside the table header, using WebGrid.

Having the code:

@grid.Table
(
    htmlAttributes: new { id = "my-list" },
    tableStyle: "grid hover-rows clickable-rows",
    columns: grid.Columns
    (
        grid.Column(
            columnName: "colName",
            header: "Name",
            style: "col-width-10"),
        grid.Column(
            columnName: "colAge",
            header: "Age",
            style: "col-width-10"),
        grid.Column(
            columnName: "colGender",
            header: "Gender",
            style: "col-width-10")
    )
)

That generates the HTML:

<table class="grid" id="my-list">
    <thead>
        <tr>
            <th scope="col">
                <a href="/MyWebSite?sort=colName&sortdir=ASC">Name</a>
            </th>
            <th scope="col">
                <a href="/MyWebSite?sort=colAge&sortdir=ASC">Age</a>
            </th>
            <th scope="col">
                <a href="/MyWebSite?sort=colGender&sortdir=ASC">Gender</a>
            </th>
        </tr>
    </thead>
    <tbody>
        the body doesn't matter 
    </tbody>
</table>

But I need IDs inside th elements:

<table class="grid" id="my-list">
    <thead>
        <tr>
            <th id="columnHeaderName" scope="col">
                <a href="/MyWebSite?sort=colName&sortdir=ASC">Name</a>
            </th>
            <th id="columnHeaderAge" scope="col">
                <a href="/MyWebSite?sort=colAge&sortdir=ASC">Age</a>
            </th>
            <th id="columnHeaderGender" scope="col">
                <a href="/MyWebSite?sort=colGender&sortdir=ASC">Gender</a>
            </th>
        </tr>
    </thead>
    <tbody>
        the body doesn't matter 
    </tbody>
</table>

The code above does not compile, is just an example to explain the problem.

Thanks in advance!

Fábio
  • 477
  • 5
  • 12
  • this is a possible duplicate of [https://stackoverflow.com/questions/11038461/simple-mvc-web-grid-issue-i-just-want-to-add-a-unique-id-to-each-row-in-a-table](https://stackoverflow.com/questions/11038461/simple-mvc-web-grid-issue-i-just-want-to-add-a-unique-id-to-each-row-in-a-table) – zgood Dec 03 '19 at 19:11
  • As it dates 2012, might be already possible to accomplish that. Also it's not related. One is trying to add to **** and other is trying to add to ****. In HTML seems similar but with webgrid they are handled differently. – Fábio Jan 13 '20 at 14:52

0 Answers0