Asked  6 Months ago    Answers:  5   Viewed   29 times

Can we have multiple <tbody> tags in same <table>? If yes then in what scenarios should we use multiple <tbody> tags?

 Answers

80

Yes you can use them, for example I use them to more easily style groups of data, like this:

thead th { width: 100px; border-bottom: solid 1px #ddd; font-weight: bold; }
tbody:nth-child(odd) { background: #f5f5f5;  border: solid 1px #ddd; }
tbody:nth-child(even) { background: #e5e5e5;  border: solid 1px #ddd; }
<table>
    <thead>
        <tr><th>Customer</th><th>Order</th><th>Month</th></tr>
    </thead>
    <tbody>
        <tr><td>Customer 1</td><td>#1</td><td>January</td></tr>
        <tr><td>Customer 1</td><td>#2</td><td>April</td></tr>
        <tr><td>Customer 1</td><td>#3</td><td>March</td></tr>
    </tbody>
    <tbody>
        <tr><td>Customer 2</td><td>#1</td><td>January</td></tr>
        <tr><td>Customer 2</td><td>#2</td><td>April</td></tr>
        <tr><td>Customer 2</td><td>#3</td><td>March</td></tr>
    </tbody>
    <tbody>
        <tr><td>Customer 3</td><td>#1</td><td>January</td></tr>
        <tr><td>Customer 3</td><td>#2</td><td>April</td></tr>
        <tr><td>Customer 3</td><td>#3</td><td>March</td></tr>
    </tbody>
</table>

You can view an example here. It'll only work in newer browsers, but that's what I'm supporting in my current application, you can use the grouping for JavaScript etc. The main thing is it's a convenient way to visually group the rows to make the data much more readable. There are other uses of course, but as far as applicable examples, this one is the most common one for me.

Tuesday, June 1, 2021
 
Xavio
answered 6 Months ago
21

You would do something like this by tapping into the scroll event handler on window, and using another table with a fixed position to show the header at the top of the page.

HTML:

<table id="header-fixed"></table>

CSS:

#header-fixed {
    position: fixed;
    top: 0px; display:none;
    background-color:white;
}

JavaScript:

var tableOffset = $("#table-1").offset().top;
var $header = $("#table-1 > thead").clone();
var $fixedHeader = $("#header-fixed").append($header);

$(window).bind("scroll", function() {
    var offset = $(this).scrollTop();

    if (offset >= tableOffset && $fixedHeader.is(":hidden")) {
        $fixedHeader.show();
    }
    else if (offset < tableOffset) {
        $fixedHeader.hide();
    }
});

This will show the table head when the user scrolls down far enough to hide the original table head. It will hide again when the user has scrolled the page up far enough again.

Working example: http://jsfiddle.net/andrewwhitaker/fj8wM/

Tuesday, June 1, 2021
 
Sujith
answered 6 Months ago
87

You can do this as:

WITH abc AS( select
             FROM ...)
, XYZ AS(select
         From abc ....) /*This one uses "abc" multiple times*/
  Select 
  From XYZ....   /*using abc, XYZ multiple times*/
Tuesday, July 27, 2021
 
Novalirium
answered 4 Months ago
79

The effect of colspan can be simulated using a table with dummy empty cells <td></td> for the slots that are to be spanned and absolutely positioning the cell that should span them. You need a relatively positioned wrapper div for the table, since you cannot directly make the table the frame of reference for positioning.

It gets rather ugly, especially since you need to worry about the row height – because making a cell absolutely positioned takes it away from table formatting. You could deal with this by using a copy of the cell content as the content of the dummy cell to be spanned. See jsfiddle.

It get complicated, so any software that cannot handle a simple colspan may fail to deal with this too (at least if it is responsible for rendering the document).

Thursday, August 19, 2021
 
mariaoialvarez
answered 4 Months ago
85

If you're trying to implement some kind of double buffering, you might want to take a look at this

I think your problem is that you need to create a bitmap, then attach the canvas to it, something like:

Bitmap bitmap = Bitmap.createBitmap(width, height, Config.RGB_565);
Canvas c = new Canvas(bitmap);

// then draw to the canvas..
// and when you're happy, draw the bitmap onto the canvas supplied to onDraw.

Just creating a canvas, doesn't make it appear on the screen.

You may also want to take a look at: this tutorial

If you have a surfaceView, then you can do something like this (don't have a compiler, but hopefully you get the gist):

SurfaceView view = (SurfaceView)findViewById(R.id.view);

SurfaceHolder holder = view.getHolder(); // save this where it can be accessed by your function

Canvas c 
try  {
    c = holder.lockCanvas();
    // draw stuff
}
finally {
    if(null != c) {
        holder.unlockCanvasAndPost(c);
    }
}
Wednesday, September 1, 2021
 
Edward Falk
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :  
Share