Permalink
Browse files

feat(table): js for responsive table

  • Loading branch information...
Freihofner, Katrin Freihofner, Katrin
Freihofner, Katrin authored and Freihofner, Katrin committed Jan 26, 2017
1 parent b0d8908 commit d7a9c0a84c915cad0c27b7c883af20e9b27d3d42
Showing with 15 additions and 8 deletions.
  1. +15 −8 src/table/table.js
View
@@ -1,24 +1,31 @@
import $ from '../js-common-components/dollar';
const init = () => {
const i = ($('th').length);
const fillData = (table) => {
const th = table.querySelectorAll('th');
const i = th.length;
const header = [];
$('th').forEach(el => {
th.forEach(el => {
header.push(el.textContent);
if (!el.getAttribute('data-initialized')) {
el.setAttribute('data-initialized', true);
}
});
let j = i - 1;
$('td').forEach(cell => {
const td = table.querySelectorAll('td');
td.forEach(cell => {
cell.setAttribute('data-th', header[i - 1 - j]);
if (j > 0) {
j--;
} else {
console.log(j);
j = i - 1;
}
});
};
const init = () => {
$('table').forEach(table => {
if (!table.getAttribute('data-initialized')) {
table.setAttribute('data-initialized', true);
fillData(table);
}
});
};
init();

0 comments on commit d7a9c0a

Please sign in to comment.