2017-10-12 110 views
0

我使用的是引导表​​举表:数据HREF后不重新排序

表中的所有行与数据HREF =联工作。 加载表后所有链接都能正常工作,但是当我重新对表进行排序(即单击“URL”列标题)时,链接不再有效。 任何想法如何解决它?

下面是测试代码:

<table class="table" id="lst_art_adm" 
         data-toggle="table" 
         data-striped="true" 
         data-search="true" 
         data-sort-name="site" 
         data-sort-order="asc" 
         data-mobile-responsive="true" 
         mobileResponsive="true"> 
    <thead> 
    <tr> 
       <th data-field="site" data-sortable="true">Site</th> 
       <th data-field="url" data-sortable="true">URL</th> 
    </tr> 
    </thead> 
    <tbody> 
    <tr id="tr-id-1" class="mrow" data-href="https://google.com"> 
     <td id="td-id-1" data-sortable="true">Google</td> 
     <td>google.com</td> 
    </tr> 
    <tr id="tr-id-2" class="mrow" data-href="https://yahoo.com"> 
     <td id="td-id-2" data-sortable="true">Yahoo</td> 
     <td>yahoo.com</td> 
    </tr> 
    </tbody> 
</table> 

$(function(){ 
    $(".mrow").on("click", function (e) { 
      window.location = $(this).data("href"); 
    }); 
}); 

jsfiddle

回答

0

我找到了解决自己:) 表必须包含在一个div元素,即类= “mytable的”。 然后jQuery的应该改变这样的:

$(function(){ 
    $(".mytable").on("click", ".table tbody tr", function() 
      window.location = $(this).data("href"); 
    }); 
}); 

则该函数将找到的行重新排序后。