首页 > 其他 > 详细

Advanced initialisation

时间:2018-06-13 19:26:18      阅读:203      评论:0      收藏:0      [点我收藏+]

1、DOM / jQuery events

$(document).ready(function() {
    var table = $(‘#example‘).DataTable();
     
    $(‘#example tbody‘).on(‘click‘, ‘tr‘, function () {
        var data = table.row( this ).data();
        alert( ‘You clicked on ‘+data[0]+‘\‘s row‘ );
    } );
} );

 

2、DataTables events

DataTables fires a number of custom events which you can bind to in the standard jQuery fashion (although note that the namespace dt must be used), allowing your code to perform custom actions when these events occur.
All custom events fired by DataTables are fired with the namespace dt in order to prevent conflicts arising with other jQuery plug-ins which also fire events. The DataTables on() method can be used like the jQuery on() method, but will automatically append the dt namespace if required.
This example shows the use of the order, search and page events by adding a notification that the event fired to an element on the page to show that they have indeed fired.

$(document).ready(function() {
    var eventFired = function ( type ) {
        var n = $(‘#demo_info‘)[0];
        n.innerHTML += ‘<div>‘+type+‘ event - ‘+new Date().getTime()+‘</div>‘;
        n.scrollTop = n.scrollHeight;      
    }
 
    $(‘#example‘)
        .on( ‘order.dt‘,  function () { eventFired( ‘Order‘ ); } )
        .on( ‘search.dt‘, function () { eventFired( ‘Search‘ ); } )
        .on( ‘page.dt‘,   function () { eventFired( ‘Page‘ ); } )
        .DataTable();
} );

 

Advanced initialisation

原文:https://www.cnblogs.com/cuteguru/p/9179349.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!