My JQuery Data Tables Did Not Load After Page Load?

On MVC when I try to table load JQuery DataTable on the page load it does not attach to my HTML table.

When I use the AJAX onComplete to trigger the JQuery table load it works fine.

My JQuery table load routine:
function onEMailNotificationsComplete() {
    alert("onEMailNotificationsComplete");
    $('#email-notifications-results table').dataTable({
        "bFilter": true,
        "bSort": true,
        "bLengthChange": false,
        "bPaginate": true,
        "sPaginationType": "full_numbers",
        "sDom": "<'row'<'col-md-6'i><'col-md-6'f>r>t<'row'<'col-md-6'i><'col-md-6'p>>",
        "bInfo": true
    });
}

HTML Table:
<table id="email-notifications-results" class="table table-bordered table-striped table-hover"> 
        <thead>
            <tr>
                <td>
                    <strong>Date E-Mail Sent</strong>
                </td>
                <td>
                    <strong>Applicant Id</strong>
                </td>
                <td>
                    <strong>Person Name</strong>
                </td>
                <td>
                    <strong>Background Check Results</strong>
                </td>
            </tr>
        </thead>
        <tbody>
            @foreach (var emailNotification in Model)
            {
                var dateEMailSent = emailNotification == null ? "" : emailNotification.DateEMailSent.ToShortDateString();

                <tr>
                    <td>
                        @Html.DisplayFor(model => dateEMailSent)
                    </td>
                    <td>
                        @Html.DisplayFor(model => emailNotification.ApplicantId)
                    </td>
                    <td>
                        @Html.DisplayFor(mode => emailNotification.PersonName)
                    </td>
                    <td>
                        @Html.DisplayFor(mode => emailNotification.BackgroundCheckResults)
                    </td>
                </tr>
            }
        </tbody>
    </table>

Open in new window


Thanks,

Dan
danielolorenzAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris StanyonWebDevCommented:
Look like your selector is wrong. Your table has the id of email-notifications-results, so your selector should be:

$('table#email-notifications-results').dataTable({

not

$('#email-notifications-results table').dataTable({
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
danielolorenzAuthor Commented:
Your solution worked.

Thanks,

Dan
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.