Skip to content

Commit

Permalink
fix tr attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
thehitechpanky committed Apr 21, 2020
1 parent 0fbed66 commit b4d3d39
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 36 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ Bootstrap

# CDN

<script src="https://cdn.jsdelivr.net/gh/TaxHeal-in/[email protected].5/html.js"></script>
<script src="https://cdn.jsdelivr.net/gh/TaxHeal-in/[email protected].5/table.js"></script>
<script src="https://cdn.jsdelivr.net/gh/TaxHeal-in/[email protected].6/html.js"></script>
<script src="https://cdn.jsdelivr.net/gh/TaxHeal-in/[email protected].6/table.js"></script>

# How to use

let headRow = [{ text: `Name` }];

let dataRows = [
let dataRows = {data: [
{text: `Pankaj`},
{text: `Ram`},
{text: `Tarun`}
];
]};

let newDynamicTable = new DynamicTable({ divId: `tableDiv`, tableId: `tableData`, headRow, dataRows, head2Row, footRow, functionArray });

Expand Down
72 changes: 40 additions & 32 deletions table.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,51 +155,59 @@ class DynamicTable {
let { addCheckboxes, checkboxClass } = this.paramObject;
let divisionNode = this._getNode(divisionName);
tableNode.appendChild(divisionNode);
let rowNode = this._getNode(`tr`);
divisionNode.appendChild(rowNode);
this._addData(rowNode, `S.No.`, dataArray, `th`, divisionName);
let trNode = this._getNode(`tr`);
divisionNode.appendChild(trNode);
this._addData(trNode, `S.No.`, dataArray, `th`, divisionName);
if (dataArray2 && dataArray2.length) {
rowNode = this._getNode(`tr`);
divisionNode.appendChild(rowNode);
this._addData(rowNode, `S.No.`, dataArray2, `th`, divisionName);
trNode = this._getNode(`tr`);
divisionNode.appendChild(trNode);
this._addData(trNode, `S.No.`, dataArray2, `th`, divisionName);
}
this._checkboxToggle(divisionName);
}

_addTableDataRows() {
let { dataRows, functionArray, addFilter, addLimit } = this.paramObject;
let { dataRows, functionArray } = this.paramObject;
this._clearNode(this.bodyNode);
if (typeof dataRows === `string`) {
this.bodyNode.insertAdjacentHTML(`beforeend`, dataRows);
} else {
let filterTerm;
if (addFilter) {
filterTerm = this.filterNode.value.toLowerCase();
}
let serialNumber = 0;
let limitNumber = 0;
let rowNode;
dataRows.forEach(currentRow => {
_addTableDataRowsFromObject();
}
if (functionArray) {
functionArray.forEach(currentObject => {
let { className, eventName, functionName } = currentObject;
this._attachFunctionToClassNodes(className, eventName, functionName);
});
}
}

_addTableDataRowsFromObject() {
let { dataRows, addFilter, addLimit } = this.paramObject;
let { className, data, id } = dataRows;
let filterTerm;
if (addFilter) {
filterTerm = this.filterNode.value.toLowerCase();
}
let serialNumber = 0;
let limitNumber = 0;
let rowNode;
if (data) {
data.forEach(currentRow => {
if (!addFilter || this._filterData(filterTerm, currentRow)) {
serialNumber++;
if (!addLimit || this.limitNode.value === `all` || this.limitNode.value >= serialNumber) {
limitNumber++;
rowNode = this._getNode(`tr`);
rowNode = this._getNode(`tr`, { className, id });
this.bodyNode.appendChild(rowNode);
this._addData(rowNode, serialNumber, currentRow, `td`, serialNumber);
}
}
});
this._clearNode(this.countNode);
let textNode = document.createTextNode(`Showing 1 to ${limitNumber} of ${serialNumber} entries`);
this.countNode.appendChild(textNode);
}
if (functionArray) {
functionArray.forEach(currentObject => {
let { className, eventName, functionName } = currentObject;
this._attachFunctionToClassNodes(className, eventName, functionName);
});
}
this._clearNode(this.countNode);
let textNode = document.createTextNode(`Showing 1 to ${limitNumber} of ${serialNumber} entries`);
this.countNode.appendChild(textNode);
}

_attachFunctionToClassNodes(className, eventName, functionName) {
Expand Down Expand Up @@ -230,18 +238,18 @@ class DynamicTable {

_addData(rowNode, serialNumber, dataArray, typeName, idSuffix) {
let { addCheckboxes, checkboxClass } = this.paramObject;
if (addCheckboxes) {
let checkboxNode = this._getNode(`input`, { className: `form-control ${checkboxClass}`, id: `${checkboxClass}_${idSuffix}`, type: `checkbox` });
let checkboxTDNode = this._getNode(typeName, { subNode: checkboxNode });
rowNode.appendChild(checkboxTDNode);
}
let serialNumberNode = this._getNode(typeName, { text: serialNumber });
rowNode.appendChild(serialNumberNode);
let cellNode;
dataArray.forEach(dataObject => {
cellNode = this._getNode(typeName, dataObject);
rowNode.appendChild(cellNode);
});
let serialNumberNode = this._getNode(typeName, { text: serialNumber });
rowNode.insertBefore(serialNumberNode, rowNode.firstChild);
if (addCheckboxes) {
let checkboxNode = this._getNode(`input`, { className: `form-control ${checkboxClass}`, id: `${checkboxClass}_${idSuffix}`, type: `checkbox` });
let checkboxTDNode = this._getNode(typeName, { subNode: checkboxNode });
rowNode.insertBefore(checkboxTDNode, rowNode.firstChild);
}
}

_addToAttribute(currentElement, name, newText) {
Expand Down

0 comments on commit b4d3d39

Please sign in to comment.