简体   繁体   中英

Condensed table with twitter bootstrap accordion

I have this table, structured in this way:

Html part:

<table id="table_div" class="table table-striped table-condensed"><tbody></tbody></table>

JS part:

var data = json_response['data'];

$("#table_div").html('<thead><tr><td>TIMESTAMP</td><td>VALUE</td></tr></thead>');

$.each(data, function(index, value) {
$('#table_div > tbody:last').append('<tr><td>' + value + '<td></tr>'); 
});   

This code generates me a table in the style of twitter bootstrap. Now I would like that the table slide up and down or is formed from more and more pages.

I don't know if I can use and in that way the accordion tool of twitter bootstrap. Or any other script. Can you help me?

EDIT

The data variable is in this type:

var data = [[1348754599, 0.0], [1348754639, 0.0], [1348754680, 0.0], [1348754721, 0.0], [1348754761, 0.0], [1348754802, 0.0], [1348754842, 0.0], [1348754883, 0.0], [1348754924, 0.0], [1348754964, 0.0], [1348755005, 0.0], [1348755045, 0.0], [1348755086, 0.0], [1348755126, 0.0], [1348755167, 0.0], [1348755208, 0.0]];

Can you setup a fiddle for this, to clarify what you need?

Update: Some corrections had to be made to the original fiddle, and the example uses the tablesorter jQuery plugin. Here is the revised HTML to make it work:

<div class="container">
    <table class="table table-striped table-bordered table-condensed"></table>
</div>

and revised JavaScript:

var data = [
    [1348754599, 0.0],
    [1348754639, 0.0],
    [1348754680, 0.0],
    [1348754721, 0.0],
    [1348754761, 0.0],
    [1348754802, 0.0],
    [1348754842, 0.0],
    [1348754883, 0.0],
    [1348754924, 0.0],
    [1348754964, 0.0],
    [1348755005, 0.0],
    [1348755045, 0.0],
    [1348755086, 0.0],
    [1348755126, 0.0],
    [1348755167, 0.0],
    [1348755208, 0.0]
];

$('table').html('<thead><tr><th>TIMESTAMP</th><th>VALUE</th></tr></thead><tbody></tbody>');

$.each(data, function (index, value) {
    $('table > tbody').append('<tr><td>' + index + '</td><td>' + value + '</td></tr>');
});

$(function () {
    $('table').tablesorter();
});

Here is a fiddle with a working example: http://jsfiddle.net/jkvr8/41/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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