简体   繁体   English

动态添加行到表和用户然后突出显示并选择一行的引导表

[英]bootstrap table that dynamically adds rows to table and user then highlight and select a row

I need in bootstrap to have table starts an empty header and if the user selects certain button it will populate the table rows.我需要在引导程序中让表格开始一个空标题,如果用户选择某个按钮,它将填充表格行。 Also at the same time the user should be able to highlight and select a row and then a certain action will take place.同时,用户应该能够突出显示并选择一行,然后会发生某个动作。 I had this all working with normal html but we wanted to add bootstrap styling.我让这一切都与普通的 html 一起工作,但我们想添加引导程序样式。 I thought that would be easy but seems extremely difficult.我认为这很容易,但似乎非常困难。 Is it even possible to do the following with bootstrap all togeter: - dynamically add rows as events happen甚至可以使用 bootstrap all togeter 执行以下操作: - 在事件发生时动态添加行

- to be able to select row and determine which row has been selected. - 能够选择行并确定已选择哪一行。

Thanks谢谢

I don't know much jQuery, the snippet below provides basic interaction - you would need to change it to suit your env.我对 jQuery 了解不多,下面的代码段提供了基本的交互 - 您需要对其进行更改以适合您的环境。 If you provide code people can give much better answers.如果您提供代码,人们可以给出更好的答案。

 $(document).on('click', 'tr', function(e) { $('tr').css('background-color', '') $(this).css('background-color', 'red') }) $('button').on('click', function(e){ $('tbody').append('<tr><td>..</td><td>..</td></tr>') }) $('select').on('change', function(e){ var value = $(this).val(), dataset = data.filter(function(item) { return item.name === value } )[0] $('tbody').html('') dataset.data.forEach(function(item) { $('tbody').append('<tr><td>'+item.name+'</td><td>'+item.age+'</td></tr>') }) }) var data = [{ name: 'people', data: [ {name: 'Kelly', age: 27}, {name: 'John', age: 22}, {name: 'Sally', age: 29}, {name: 'Mike', age: 26}, ] },{ name: 'planets', data: [ {name: 'Pluto', age: 2700}, {name: 'Earth', age: 2200}, {name: 'Moon', age: 2900}, {name: 'Sun', age: 2600}, ] }] data.forEach(function(data) { $('select').append('<option value="' + data.name + '">' + data.name + '</option>') })
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <select></select> <table> <thead> <tr> <th>Name</th> <th>Age</th> </tr> </thead> <tbody> </tbody> </table>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM