0

I have datatable in _layout that works fine all other tables except this particular one I have in a partial view perhaps because of the way the data is loaded.

_layout.cshtml

    $('.dataTableList').DataTable({ responsive: true, "autoWidth": false });

Detail.cshtml

    <div class="inventory" [email protected]("Inventory")>...</div>

Load div table:

    $('.inventory').each(function (index, item) {
        var url = $(item).data("url");
        if (url && url.length > 0) {
            $(item).load(url); 
        }
    });

Controller-Action

    public ActionResult Inventory()
    {              
        return PartialView("Inventory", inventoryService.Get());
    }

Partial Inventory view

    <table class="table table-striped dataTableList">
        <thead><tr><th></th></tr></thead> <tbody>...</tbody></table>

How do I get datatable initialization from _layout to work on this table? I see that if i initialize datatable only in partial view and not in layout, it works fine. But then I would have to initialize it on all my other partial views individually. There has to be a better way. Would appreciate your help.

1
  • You might get more help if you add tags for the framework you're using as well. Aug 17, 2017 at 21:18

1 Answer 1

0

after loading your partial view html, try to call something like $('#partialViewDataTable').DataTable().ajax.reload();

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.