jquery - Datatable Javascript Link not working on 2nd page -
i have list of data in table , using datatable plugin pagination.
however, last column link. when go 2nd page cannot click link, link opens on first page of table.
when did not have datatable linked work, when added didnt work...
my code:
<table id="partsresultlistgrid" class="table table-striped table-bordered"> <thead> <tr> <th> @html.displaynamefor(model => model.partsrequestordernum) </th> <th> @html.displaynamefor(model => model.call_num) </th> <th> @html.displaynamefor(model => model.detailview) </th> </tr> </thead> <tbody> @foreach (var item in model) { <tr> <td> @html.displayfor(modelitem => item.partsrequestordernum) </td> <td> @html.displayfor(modelitem => item.call_num) </td> <td> <div data-callno='@item.partsrequestordernum' data-url="@url.action("getpartsinfo", "parts")"> <div class="partsviewsubmit toolbaricon"> <div class="toolbaricontext">view</div> </div> </div> </td> </tr> } </tbody> </table>
javascript:
<script type="text/javascript"> $(document).ready(function () { $('#partsresultlistgrid').datatable({ "bsort": false, }); }); </script>
any idea why happening?
my ajax link inside opens link:
$('.partsviewsubmit').click(function () { $.ajax({ type: "get", url: $(this).parent().data("url"), data: { partsrequestordernum: $(this).parent().data("callno") }, success: function (data) { $("#partsdetail").html(data); }, }); });
you need use delegated event :
delegated events have advantage can process events descendant elements added document @ later time. picking element guaranteed present @ time delegated event handler attached, can use delegated events avoid need attach , remove event handlers.
so in case, instead :
$(document.body).on('click', '.partsviewsubmit', function() { $.ajax({ ... }); });
Comments
Post a Comment