Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"widthIncludesScrollbar" parameter to handle scrollbar inside the container #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions jquery.tablescroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,17 @@ OTHER DEALINGS IN THE SOFTWARE.
var diff = wrapper_width-width;

// assume table will scroll
wrapper.css({width:((width-diff)+settings.scrollbarWidth)+'px'});
tb.css('width',(width-diff)+'px');
if (!settings.widthIncludesScrollbar) {
wrapper.css({width:((width-diff)+settings.scrollbarWidth)+'px'});
tb.css('width',(width-diff)+'px');
} else {
tb.css('width',(width-settings.scrollbarWidth)+'px');
}

if (tb.outerHeight() <= settings.height)
{
wrapper.css({height:'auto',width:(width-diff)+'px'});
tb.css('width',width+'px');
flush = false;
}

Expand All @@ -128,16 +133,18 @@ OTHER DEALINGS IN THE SOFTWARE.
var tbody_tr_first = $('tbody tr:first',tb);
var tfoot_tr_first = $('tfoot tr:first',tb);

// remember width of last cell
var w = 0;
var cell_widths = [];

$('th, td',thead_tr_first).each(function(i)
{
w = $(this).width();
cell_widths[i] = $(this).width();
});

$('th:eq('+i+'), td:eq('+i+')',thead_tr_first).css('width',w+'px');
$('th:eq('+i+'), td:eq('+i+')',tbody_tr_first).css('width',w+'px');
if (has_tfoot) $('th:eq('+i+'), td:eq('+i+')',tfoot_tr_first).css('width',w+'px');
$('th, td',thead_tr_first).each(function(i)
{
$('th:eq('+i+'), td:eq('+i+')',thead_tr_first).css('width',cell_widths[i]+'px');
$('th:eq('+i+'), td:eq('+i+')',tbody_tr_first).css('width',cell_widths[i]+'px');
if (has_tfoot) $('th:eq('+i+'), td:eq('+i+')',tfoot_tr_first).css('width',cell_widths[i]+'px');
});

if (has_thead)
Expand All @@ -156,7 +163,7 @@ OTHER DEALINGS IN THE SOFTWARE.

if (flush)
{
$('tr:first th:last, tr:first td:last',tbh).css('width',(w+settings.scrollbarWidth)+'px');
$('tr:first th:last, tr:first td:last',tbh).css('width',(cell_widths[cell_widths.length-1]+settings.scrollbarWidth)+'px');
tbh.css('width',wrapper.outerWidth() + 'px');
}
}
Expand All @@ -167,7 +174,7 @@ OTHER DEALINGS IN THE SOFTWARE.

if (flush)
{
$('tr:first th:last, tr:first td:last',tbf).css('width',(w+settings.scrollbarWidth)+'px');
$('tr:first th:last, tr:first td:last',tbf).css('width',(cell_widths[cell_widths.length-1]+settings.scrollbarWidth)+'px');
tbf.css('width',wrapper.outerWidth() + 'px');
}
}
Expand All @@ -182,7 +189,9 @@ OTHER DEALINGS IN THE SOFTWARE.
flush: true, // makes the last thead and tbody column flush with the scrollbar
width: null, // width of the table (head, body and foot), null defaults to the tables natural width
height: 100, // height of the scrollable area
containerClass: 'tablescroll' // the plugin wraps the table in a div with this css class
containerClass: 'tablescroll', // the plugin wraps the table in a div with this css class
widthIncludesScrollbar: false // if true then the width parameter is equal to (table width + scrollbar width)
// otherwise width is always equal to table width regarding scrollbar.
};

})(jQuery);