0

I am using jQuery DataTables 1.9.4. On trying to use the datatable module I am getting the above error. Going through SO, I have seen a lot of people advising to use the uppercase DataTable({}) instead of the lowercase dataTable({}), but still get the error.

var table = $("#example1").DataTable();
        $('#example1 tbody').on('click', 'tr', function () {
            var data = table.row(this).data();                
        });

Note this is an ASP.NET MVC Project

<table id="example1" class="table table-bordered table-striped">
                                        <thead>
                                            <tr>
                                                <th>@Html.DisplayNameFor(model => model.FirstName)</th>
                                                <th>@Html.DisplayNameFor(model => model.Surname)</th>
                                                <th>@Html.DisplayNameFor(model => model.MiddleName)</th>
                                                <th>@Html.DisplayNameFor(model => model.DateOfBirth)</th>
                                                <th>@Html.DisplayNameFor(model => model.Department)</th>

                                            </tr>
                                        </thead>
                                        <tbody>
                                            @foreach (var item in Model)
                                            {
                                                <tr>
                                                    <td>@Html.DisplayFor(modelItem => item.FirstName)</td>
                                                    <td>@Html.DisplayFor(modelItem => item.Surname)</td>
                                                    <td>@Html.DisplayFor(modelItem => item.MiddleName)</td>
                                                    <td>@Html.DisplayFor(modelItem => item.DateOfBirth)</td>
                                                    <td>@Html.DisplayFor(modelItem => item.Department)</td>
                                              </tr>
                                            }
                                        </tbody>
                                    </table>
8
  • Is your DataTable being initialized properly? Show us the table html Commented Mar 5, 2016 at 22:18
  • @EricGuan I have updated my question with the table markup Commented Mar 6, 2016 at 3:04
  • I am quite sure you have a cache problem. Be sure your browser is loading the correct version of your JS. Even if your markup or something else was invalid, even if you get nasty alerts while initializing - you would still receive a table reference with an API you can work on. Commented Mar 6, 2016 at 3:31
  • @davidkonrad I launch my browser with Chrome's Dev tool always opened, so caching is not a problem Commented Mar 6, 2016 at 3:54
  • @kolexinfos, that does not matter if you not have caching turned off :) network -> disable cache -> reload Commented Mar 6, 2016 at 4:38

1 Answer 1

1

You're using jQuery DataTables 1.9.4.

API method row() is only available in jQuery DataTables 1.10+.

See if you can upgrade your library, it is backward compatible.

Sign up to request clarification or add additional context in comments.

2 Comments

is this the same for rows mine is not finding it in the same verison
@csharpdudeni77, yes, it's the same for all API methods listed on this page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.