Bootstrap table - cannot add click event on tr

I am using the Bootstrap table ( http://wenzhixin.net.cn/p/bootstrap-table/docs/index.html )

I am trying to add a click event

$('tr').click(function(){ console.log('test'); }); 

but that will not work. I know that there is an event in the bootstrap-table library, but for me it is important to use it with jQuery.click. Do you know what blocks this event in the bootstrap source code? I tried to remove all the ".off" from bootstrap-table.js, but that did not help.

+6
source share
4 answers

I think you can use the onClickRow event or click-row.bs.table instead of the tr click event, here is the documentation and examples .

Code example:

 // Fires when user click a row $('#table').bootstrapTable({ onClickRow: function (row, $element) { // row: the record corresponding to the clicked row, // $element: the tr element. } }); // or $('#table').on('click-row.bs.table', function (e, row, $element) { // console.log(row, $element); }); 

(I am the author of Bootstrap Table, I hope to help you!)

+24
source

try it

  $('table').on('click', 'tr' , function (event) { console.log('test'); }); 
+3
source

I will try with this code, success to get the find td (td: eq (1)) value.

  $('#tbname').on('change', 'tr' , function (event) { if($('.selected')){ kode =$('.selected').closest('tr').find('td:eq(1)').text(); $("input").val(kode); } 
0
source

I started using this useful plugin just a few days ago, I ran into the same problem and the user wenyi gave a good answer, but was rather complicated for people who are starting out.

 /* You have this table */ <table id="my-table"> <tr> <a href="#" class="my-link">Details</a> </tr> </table> /* You have to options to detect this click (and more) */ /* Normal way */ $(".my-link").click(function(){ //do something }); /* To solve this click detection problem you will need to use this */ $("#my-table").on('click','.my-link',function(){ //do something }); 

Why? because every time one html element is added dynamically in the DOM, they cannot be detected with the normal click function.

Additonally:

 /* Even you can use this method, but the performance is less */ $(document).on('click','.my-link',function(){ //do something }); 
0
source

Source: https://habr.com/ru/post/977223/


All Articles