Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
532 views
in Technique[技术] by (71.8m points)

javascript - popover on hover not working on second page of datatable

I added content of one column dynamically...

 for (var i = 0; i < data.length; i++) {
   data.referred_by='<a href="#" data-toggle="popover" class="" title="'+temp[i].referred_by+'"data-trigger="hover" data-content="Total Referrals :'+temp[i].as_count+'">'+temp[i].referred_by+'</a>'
 }

and Following code is of creating datatable

$('#datatable4').dataTable({
  'paging':   true,  // Table pagination
  'ordering': true,  // Column ordering 
  'info':     true,  // Bottom left status text
  "aaData" : data,

  aoColumns: [
    { mData: 'index' },
    { mData: 'patient_name' },
    { mData: 'age' },
    { mData: 'gender' },
    { mData: 'mobile_no' },
    { mData: 'email_id' },
    { mData: 'request_status' },
    { mData: 'referred_by' },
    { mData: 'ref_to_img'},
    { mData: 'ref_by_img'}
  ]

and in ready function I added

 $('[data-toggle="popover"]').popover();

but in datatable only on first page popover on hover is working... and on second page onwards its not working.... is there any solution for this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need to reinitialize the popovers each time the dataTable is redrawn. $('[data-toggle="popover"]').popover() will only initialize those popovers visible at the time the code is executed, not the popovers in for example page #2. Execute popover() in the drawCallback() callback instead :

$('#datatable4').dataTable({
  ...
  drawCallback: function() {
    $('[data-toggle="popover"]').popover();
  }  
})

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...