Skip to content
This repository has been archived by the owner on May 30, 2021. It is now read-only.

Commit

Permalink
Fixed columns bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Mobius1 committed Aug 31, 2017
1 parent 4e62529 commit 7885baf
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 39 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ A lightweight, dependency-free javascript HTML table plugin. Similar to jQuery D
* moment.js integration for sorting columns with datetime strings (experimental, v1.2.3 and above)


[Documentation](https://github.com/Mobius1/Vanilla-DataTables/wiki) | [Latest Stable Version](https://github.com/Mobius1/Vanilla-DataTables/releases/tag/1.3.5) | [Latest Version](https://github.com/Mobius1/Vanilla-DataTables/releases/tag/1.4.1)
[Documentation](https://github.com/Mobius1/Vanilla-DataTables/wiki) | [Latest Stable Version](https://github.com/Mobius1/Vanilla-DataTables/releases/tag/1.3.5) | [Latest Version](https://github.com/Mobius1/Vanilla-DataTables/releases/tag/1.4.2)

---

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vanilla-datatables",
"version": "1.4.1",
"version": "1.4.2",
"main": "src/vanilla-dataTables.js",
"ignore": [
".gitattributes",
Expand Down
2 changes: 1 addition & 1 deletion dist/vanilla-dataTables.min.css

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

4 changes: 2 additions & 2 deletions dist/vanilla-dataTables.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vanilla-datatables",
"version": "1.4.1",
"version": "1.4.2",
"description": "A lightweight, dependency-free javascript HTML table plugin.",
"main": "src/vanilla-dataTables.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/vanilla-dataTables.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright (c) 2015-2017 Karl Saunders (http://mobius.ovh)
* Licensed under MIT (http://www.opensource.org/licenses/mit-license.php)
*
* Version: 1.4.1
* Version: 1.4.2
*
*/

Expand Down
72 changes: 40 additions & 32 deletions src/vanilla-dataTables.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright (c) 2015-2017 Karl Saunders (http://mobius.ovh)
* Licensed under MIT (http://www.opensource.org/licenses/mit-license.php)
*
* Version: 1.4.1
* Version: 1.4.2
*
*/
(function(root, factory) {
Expand All @@ -31,7 +31,7 @@
*/
var defaultConfig = {
perPage: 10,
perPageSelect: [5,10,15,20,25],
perPageSelect: [5, 10, 15, 20, 25],

sortable: true,
searchable: true,
Expand Down Expand Up @@ -295,7 +295,7 @@
else if (d - e != 1) {
var f = createElement("li", {
class: "ellipsis",
html: '<a href="#">'+ellipsis+'</a>'
html: '<a href="#">' + ellipsis + '</a>'
});
i.push(f);
}
Expand Down Expand Up @@ -619,7 +619,7 @@
this.dt.headings.push(th);

each(this.dt.data, function(i, row) {
if ( data.rows[i] ) {
if (data.rows[i]) {
td = document.createElement("td");

if (data.rows[i].nodeName) {
Expand Down Expand Up @@ -654,10 +654,12 @@
*/
Columns.prototype.remove = function(select) {

if ( isArray(select) ) {
if (isArray(select)) {

// Remove in reverse otherwise the indexes will be incorrect
select.sort(function(a, b) { return b - a; });
select.sort(function(a, b) {
return b - a;
});

each(select, function(i, column) {
this.remove(column);
Expand Down Expand Up @@ -778,7 +780,9 @@

if (isArray(select)) {
// Remove in reverse otherwise the indexes will be incorrect
select.sort(function(a, b) { return b - a; });
select.sort(function(a, b) {
return b - a;
});

each(select, function(i, row) {
this.dt.data.splice(row, 1);
Expand Down Expand Up @@ -963,6 +967,8 @@
data: data
});

that.setColumns();

that.emit("datatable.ajax.success", e, xhr);
} else {
that.emit("datatable.ajax.error", e, xhr);
Expand Down Expand Up @@ -1049,7 +1055,9 @@
}
}

that.setColumns();
if (!o.ajax) {
that.setColumns();
}

// Build
that.wrapper = createElement("div", {
Expand Down Expand Up @@ -1319,28 +1327,28 @@
*/
proto.renderHeader = function() {
var that = this;
if ( that.headings && that.headings.length ) {
each(that.headings, function(i, th) {
if (classList.contains(th.firstElementChild, "dataTable-sorter")) {
th.innerHTML = th.firstElementChild.innerHTML;
}

th.sortable = th.getAttribute("data-sortable") !== "false";
if (that.headings && that.headings.length) {
each(that.headings, function(i, th) {
if (classList.contains(th.firstElementChild, "dataTable-sorter")) {
th.innerHTML = th.firstElementChild.innerHTML;
}

th.originalCellIndex = i;
if (that.options.sortable && th.sortable) {
var link = createElement("a", {
href: "#",
class: "dataTable-sorter",
html: th.innerHTML
});
th.sortable = th.getAttribute("data-sortable") !== "false";

th.innerHTML = "";
th.setAttribute("data-sortable", "");
th.appendChild(link);
}
th.originalCellIndex = i;
if (that.options.sortable && th.sortable) {
var link = createElement("a", {
href: "#",
class: "dataTable-sorter",
html: th.innerHTML
});
}

th.innerHTML = "";
th.setAttribute("data-sortable", "");
th.appendChild(link);
}
});
}
};

/**
Expand Down Expand Up @@ -1585,11 +1593,11 @@

var widths = [];
each(cells, function(i, cell) {
var ow = cell.offsetWidth;
var w = ow / this.rect.width * 100;
widths.push(w);
this.columnWidths[i] = ow;
}, this);
var ow = cell.offsetWidth;
var w = ow / this.rect.width * 100;
widths.push(w);
this.columnWidths[i] = ow;
}, this);

each(this.data, function(idx, row) {
each(row.cells, function(i, cell) {
Expand Down

0 comments on commit 7885baf

Please sign in to comment.