Skip to content

Commit

Permalink
No header support
Browse files Browse the repository at this point in the history
  • Loading branch information
jerrylow committed Feb 9, 2018
1 parent 0fb9d4a commit 3a9dcc7
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 30 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Define the breakpoint (viewport's width) when the table will engage in responsiv

`integer` `default: null`

Define the breakpoint of the table's container when the table will engage in responsive mode.
Define the breakpoint of the table's container when the table will engage in responsive mode.

### contentWrap

Expand Down Expand Up @@ -48,6 +48,12 @@ When the library is initialize create a div wrapper around the table with class

When true, empty cells will be shown.

### header

`boolean` `default: true`

Set to false if table does not have a header row. Table will just be responsive with table body and optional footer.

## Methods

### start
Expand Down
5 changes: 5 additions & 0 deletions basictable.css
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,8 @@ table.bt tbody td .bt-content {
overflow: auto;
-webkit-overflow-scrolling: touch;
}

table.bt.bt--no-header tfoot td::before,
table.bt.bt--no-header tbody td::before {
display: none;
}
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "basictable",
"version": "1.0.6",
"version": "1.0.7",
"license": "MIT",
"main": [
"jquery.basictable.js",
Expand Down
65 changes: 38 additions & 27 deletions jquery.basictable.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,37 @@
table.wrap('<div class="bt-wrapper"></div>');
}

var format = '';
// Table Header
if (data.header) {
var format = '';

if (table.find('thead tr th').length) {
format = 'thead th';
}
else if (table.find('tbody tr th').length) {
format = 'tbody tr th';
}
else if (table.find('th').length) {
format = 'tr:first th';
}
else {
format = 'tr:first td';
}
if (table.find('thead tr th').length) {
format = 'thead th';
}
else if (table.find('tbody tr th').length) {
format = 'tbody tr th';
}
else if (table.find('th').length) {
format = 'tr:first th';
}
else {
format = 'tr:first td';
}

$.each(table.find(format), function() {
var $heading = $(this);
var colspan = parseInt($heading.attr('colspan'), 10) || 1;
var row = $heading.closest('tr').index();
$.each(table.find(format), function() {
var $heading = $(this);
var colspan = parseInt($heading.attr('colspan'), 10) || 1;
var row = $heading.closest('tr').index();

if (!headings[row]) {
headings[row] = [];
}
if (!headings[row]) {
headings[row] = [];
}

for (var i = 0; i < colspan; i++) {
headings[row].push($heading);
}
});
for (var i = 0; i < colspan; i++) {
headings[row].push($heading);
}
});
}

// Table Body
$.each(table.find('tbody tr'), function() {
Expand All @@ -62,6 +65,7 @@
}
else {
var cellIndex = $cell.index();

var headingText = '';

for (var j = 0; j < headings.length; j++) {
Expand Down Expand Up @@ -114,20 +118,25 @@
var start = function(table, data) {
table.addClass('bt');

if (!data.header) {
table.addClass('bt--no-header');
}

if (data.tableWrap) {
table.parent('.bt-wrapper').addClass('active');
}
};

var end = function(table, data) {
table.removeClass('bt');
table.removeClass('bt bt--no-header');

if (data.tableWrap) {
table.parent('.bt-wrapper').removeClass('active');
}
};

var destroy = function(table, data) {
table.removeClass('bt bt--no-header');
table.find('td').removeAttr('data-th');

if (data.tableWrap) {
Expand Down Expand Up @@ -182,7 +191,8 @@
forceResponsive: settings.forceResponsive,
noResize: settings.noResize,
tableWrap: settings.tableWrap,
showEmptyCells: settings.showEmptyCells
showEmptyCells: settings.showEmptyCells,
header: settings.header
};
// Maintain the original functionality/defaults
if(vars.breakpoint === null && vars.containerBreakpoint === null){
Expand Down Expand Up @@ -211,6 +221,7 @@
forceResponsive: true,
noResize: false,
tableWrap: false,
showEmptyCells: false
showEmptyCells: false,
header: true
};
})(jQuery);
2 changes: 1 addition & 1 deletion jquery.basictable.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3a9dcc7

Please sign in to comment.