Carpathea
Carpathea

Reputation: 107

DataTables and For Loops

I have a DataTable

 <table class="tblData" id="dataTable">
    <thead>
        <tr class="tal">
            <th class="nw">Email</th>
            <th class="nw">Type</th>
            <th class="nw">Issue Id</th>
            <th class="nw">Credits Remaining</th>
            <th class="nw">Start Date</th>
            <th class="nw">End Date</th>
        </tr>
    </thead>
    <tbody>
    <% foreach (var r in Model.GiftVouchers) {  %>
        <tr>
            <td><%: r.Email %></td>
            <td><%: r.SingleIssue == true ? "Single Issue" : (r.CreditExpiry == "Credit" ? "Credit Sub" : "Expiry Sub") %></td>
            <td><%: r.IssueInformation %></td>
            <td><%: r.CreditExpiry == "Credit" ? r.CreditsRemaining.ToString() : "N/A" %></td>
            <td><%: r.StartDate %></td>
            <td><%: r.EndDate %></td>
        </tr>
    </tbody>
    <%} %>
</table>

This issue i have is that because the for loop is acting upon a single <tr> the data table seems to think that there is only one row and displays all the data as a single row so pagination etc isnt working. I cant think of a way to get the datatable to know about the for loop and create seperate rows per iteration. Is it possible with datatables to do this? If not what other methods are available bearing in mind that i have potentially 400 plus data entries.

Upvotes: 0

Views: 42

Answers (1)

Christos
Christos

Reputation: 53958

You should place the closing body bracket </tbody> under the <%} %>.

Upvotes: 1

Related Questions