DataTable Javascript Link not working on 2nd page

來源:互聯網
上載者:User

標籤:div   move   alert   auto   proc   delegate   roc   bsp   nbsp   

$(document).ready(function () {        var otable = $(‘#tbl-resources‘).dataTable(               {                   bJQueryUI: false, bFilter: true, bPaginate: true, bSort: false, bInfo: true,                   "oLanguage": { "sSearch": "Click on column to sort / Search all columns for:" }                   , "sPaginationType": "simple_numbers", "bAutoWidth": false,                   "sDom": ‘<"row view-filter" <"col-sm-6"<"#ddl-category">><"col-sm-6"<"pull-right"f>>>t<"row view-pager"<"col-sm-7"<"pull-left"l><"pull-right"i>><"col-sm-5"<"pull-right"p>>>‘,                   "aoColumns": [                                 null,                                 null,                                 null,                                { "width": "40%" }                   ],                   "buttons": [                            {                                extend: ‘collection‘,                                text: ‘Select Resource Category‘,                                "fnClick": function (nButton, oConfig, oFlash) {                                    alert(‘Mouse click‘);                                }                            }                   ]               });        $label = $(‘<label/>‘).text(‘Resource Category:‘).appendTo(‘#ddl-category‘)        $label.append("&nbsp;&nbsp;&nbsp;&nbsp;");        //insert the select and some options        $select = $(‘<select/>‘, { ‘class‘: ‘form-control‘ }).appendTo(‘#ddl-category‘)        @foreach (var item in Model.ResourceCategories)        {            <Text>        $(‘<option/>‘).val(‘@item.Value‘).text(‘@item.Text‘).appendTo($select);        </Text>        }        otable.$(".editResource").on(‘click‘, function () {            var category = $(‘#ddl-category :selected‘).val();            alert(category);            var overridden = $(this).data(‘overridden‘);            var resourceId = $(this).attr(‘data-resourceId‘);            $.ajax({                url: ‘@Url.Action("EditResource", "Correspondent")‘,                type: "POST",                data: { selectedId: resourceId, selectedCategory: category, IsOverriddenResource: overridden },            }).success(function (result) {                $(‘#div-edit-modal‘).html(result);                $(‘#edit-modal‘).modal(‘show‘);            });        });    });

My last column in Datatable is link, but only work on the first page, whenever I changed the page number or number shown on page the links were not working.

Solution: Delegated events have the advantage that they can process events from
      descendant elements that are added to the document at a later time. By
      picking an element that is guaranteed to be present at the time the
      delegated event handler is attached, you can use delegated events to
      avoid the need to frequently attach and remove event handlers.

So, instead of using

$(".editResource").click(function () {

need to use dataTables.$()   which is

otable.$(‘.editResource‘).on(‘click‘, function () {

DataTable Javascript Link not working on 2nd page

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.