Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.4.0
### Enhancements & Features
- Store sort order, column selection and row count in browser's localStorage

## 1.3.3
### Enhancements & Features
- Update dependencies to 2018 versions, eliminating 72 vulnerabilities.
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"accessibility",
"bootstrap"
],
"version": "1.3.5",
"version": "1.4.0",
"authors": [
{
"name": "Rafael Staib",
Expand Down
Binary file removed dist/jquery.bootgrid-1.3.5.zip
Binary file not shown.
Binary file added dist/jquery.bootgrid-1.4.0.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/jquery.bootgrid.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* jQuery Bootgrid v1.3.5 - 11/17/2021
* jQuery Bootgrid v1.4.0 - 12/31/2021
* Copyright © 2014-2015 Rafael J. Staib; Copyright © 2018-2021 Deciso B.V. (http://www.jquery-bootgrid.com)
* Licensed under the MIT license. See LICENSE.txt for more details.
*/
Expand Down
2 changes: 1 addition & 1 deletion dist/jquery.bootgrid.fa.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* jQuery Bootgrid v1.3.5 - 11/17/2021
* jQuery Bootgrid v1.4.0 - 12/31/2021
* Copyright © 2014-2015 Rafael J. Staib; Copyright © 2018-2021 Deciso B.V. (http://www.jquery-bootgrid.com)
* Licensed under the MIT license. See LICENSE.txt for more details.
*/
Expand Down
27 changes: 22 additions & 5 deletions dist/jquery.bootgrid.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* jQuery Bootgrid v1.3.5 - 11/17/2021
* jQuery Bootgrid v1.4.0 - 12/31/2021
* Copyright © 2014-2015 Rafael J. Staib; Copyright © 2018-2021 Deciso B.V. (http://www.jquery-bootgrid.com)
* Licensed under the MIT license. See LICENSE.txt for more details.
*/
Expand Down Expand Up @@ -78,6 +78,7 @@ function init()

loadColumns.call(this); // Loads columns from HTML thead tag
this.selection = this.options.selection && this.identifier != null;
this.rowCount = localStorage.getItem('rowCount[' + this.uid + ']') || this.rowCount;
loadRows.call(this); // Loads rows from HTML tbody tag if ajax is false
prepareTable.call(this);
renderTableHeader.call(this);
Expand Down Expand Up @@ -112,6 +113,8 @@ function loadColumns()
{
var $this = $(this),
data = $this.data(),
visibilityStorage = localStorage.getItem('visibleColumns[' + that.uid + '][' + data.columnId + ']'),
sortingStorage = localStorage.getItem('sortColumns[' + that.uid + '][' + data.columnId + ']'),
column = {
id: data.columnId,
identifier: that.identifier == null && data.identifier || false,
Expand All @@ -122,10 +125,13 @@ function loadColumns()
cssClass: data.cssClass || "",
headerCssClass: data.headerCssClass || "",
formatter: that.options.formatters[data.formatter] || null,
order: (!sorted && (data.order === "asc" || data.order === "desc")) ? data.order : null,
order: !sorted ?
(sortingStorage === null ? (data.order === "asc" || data.order === "desc" ? data.order : null) :
(sortingStorage === "asc" || sortingStorage === "desc" ? sortingStorage : null)) :
null, // If no other column is sorted already (or multiSort is enabled), check if sorting was stored
searchable: !(data.searchable === false), // default: true
sortable: !(data.sortable === false), // default: true
visible: !(data.visible === false), // default: true
visible: visibilityStorage === null ? !(data.visible === false) : (visibilityStorage === 'true'), // default: true
visibleInSelection: !(data.visibleInSelection === false), // default: true
width: ($.isNumeric(data.width)) ? data.width + "px" :
(typeof(data.width) === "string") ? data.width : null
Expand Down Expand Up @@ -393,9 +399,10 @@ function renderColumnSelection(actions)

var $this = $(this),
checkbox = $this.find(checkboxSelector);
localStorage.setItem('visibleColumns[' + that.uid + '][' + column.id + ']', checkbox.prop("checked"));
if (!checkbox.prop("disabled"))
{
column.visible = checkbox.prop("checked");
column.visible = localStorage.getItem('visibleColumns[' + that.uid + '][' + column.id + ']') === 'true';
var enable = that.columns.where(isVisible).length > 1;
$this.parents(itemsSelector).find(selector + ":has(" + checkboxSelector + ":checked)")
._bgEnableAria(enable).find(checkboxSelector)._bgEnableField(enable);
Expand Down Expand Up @@ -552,13 +559,14 @@ function renderRowCountSelection(actions)
{
var item = $(tpl.actionDropDownItem.resolve(getParams.call(that,
{ text: getText(value), action: value })))
._bgSelectAria(value === that.rowCount)
._bgSelectAria(value.toString() === that.rowCount.toString())
.on("click" + namespace, menuItemSelector, function (e)
{
e.preventDefault();

var $this = $(this),
newRowCount = $this.data("action");
localStorage.setItem('rowCount[' + that.uid + ']', newRowCount);
if (newRowCount !== that.rowCount)
{
// todo: sophisticated solution needed for calculating which page is selected
Expand Down Expand Up @@ -843,11 +851,16 @@ function setTableHeaderSortDirection(element)
{
element.parents("tr").first().find(iconSelector).removeClass(css.iconDown + " " + css.iconUp);
this.sortDictionary = {};
for (var i = 0; i < this.columns.length; i++)
{
localStorage.removeItem('sortColumns[' + this.uid + '][' + this.columns[i].id + ']');
}
}

if (sortOrder && sortOrder === "asc")
{
this.sortDictionary[columnId] = "desc";
localStorage.setItem('sortColumns[' + this.uid + '][' + columnId + ']', "desc");
icon.removeClass(css.iconUp).addClass(css.iconDown);
}
else if (sortOrder && sortOrder === "desc")
Expand All @@ -863,17 +876,20 @@ function setTableHeaderSortDirection(element)
}
}
this.sortDictionary = newSort;
localStorage.removeItem('sortColumns[' + this.uid + '][' + columnId + ']');
icon.removeClass(css.iconDown);
}
else
{
this.sortDictionary[columnId] = "asc";
localStorage.setItem('sortColumns[' + this.uid + '][' + columnId + ']', "asc");
icon.removeClass(css.iconDown).addClass(css.iconUp);
}
}
else
{
this.sortDictionary[columnId] = "asc";
localStorage.setItem('sortColumns[' + this.uid + '][' + columnId + ']', "asc");
icon.addClass(css.iconUp);
}
}
Expand Down Expand Up @@ -997,6 +1013,7 @@ var Grid = function(element, options)
this.header = null;
this.footer = null;
this.xqr = null;
this.uid = window.location.pathname + "#" + this.element.attr('id');

// todo: implement cache
};
Expand Down
2 changes: 1 addition & 1 deletion dist/jquery.bootgrid.min.css

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

2 changes: 1 addition & 1 deletion dist/jquery.bootgrid.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
Expand Up @@ -2,7 +2,7 @@
"name": "jquery-bootgrid",
"namespace": "jquery.bootgrid",
"title": "jQuery Bootgrid",
"version": "1.3.5",
"version": "1.4.0",
"description": "Nice, sleek and intuitive. A grid control especially designed for bootstrap.",
"homepage": "http://www.jquery-bootgrid.com",
"author": {
Expand Down
24 changes: 20 additions & 4 deletions src/internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ function init()

loadColumns.call(this); // Loads columns from HTML thead tag
this.selection = this.options.selection && this.identifier != null;
this.rowCount = localStorage.getItem('rowCount[' + this.uid + ']') || this.rowCount;
loadRows.call(this); // Loads rows from HTML tbody tag if ajax is false
prepareTable.call(this);
renderTableHeader.call(this);
Expand Down Expand Up @@ -102,6 +103,8 @@ function loadColumns()
{
var $this = $(this),
data = $this.data(),
visibilityStorage = localStorage.getItem('visibleColumns[' + that.uid + '][' + data.columnId + ']'),
sortingStorage = localStorage.getItem('sortColumns[' + that.uid + '][' + data.columnId + ']'),
column = {
id: data.columnId,
identifier: that.identifier == null && data.identifier || false,
Expand All @@ -112,10 +115,13 @@ function loadColumns()
cssClass: data.cssClass || "",
headerCssClass: data.headerCssClass || "",
formatter: that.options.formatters[data.formatter] || null,
order: (!sorted && (data.order === "asc" || data.order === "desc")) ? data.order : null,
order: !sorted ?
(sortingStorage === null ? (data.order === "asc" || data.order === "desc" ? data.order : null) :
(sortingStorage === "asc" || sortingStorage === "desc" ? sortingStorage : null)) :
null, // If no other column is sorted already (or multiSort is enabled), check if sorting was stored
searchable: !(data.searchable === false), // default: true
sortable: !(data.sortable === false), // default: true
visible: !(data.visible === false), // default: true
visible: visibilityStorage === null ? !(data.visible === false) : (visibilityStorage === 'true'), // default: true
visibleInSelection: !(data.visibleInSelection === false), // default: true
width: ($.isNumeric(data.width)) ? data.width + "px" :
(typeof(data.width) === "string") ? data.width : null
Expand Down Expand Up @@ -383,9 +389,10 @@ function renderColumnSelection(actions)

var $this = $(this),
checkbox = $this.find(checkboxSelector);
localStorage.setItem('visibleColumns[' + that.uid + '][' + column.id + ']', checkbox.prop("checked"));
if (!checkbox.prop("disabled"))
{
column.visible = checkbox.prop("checked");
column.visible = localStorage.getItem('visibleColumns[' + that.uid + '][' + column.id + ']') === 'true';
var enable = that.columns.where(isVisible).length > 1;
$this.parents(itemsSelector).find(selector + ":has(" + checkboxSelector + ":checked)")
._bgEnableAria(enable).find(checkboxSelector)._bgEnableField(enable);
Expand Down Expand Up @@ -542,13 +549,14 @@ function renderRowCountSelection(actions)
{
var item = $(tpl.actionDropDownItem.resolve(getParams.call(that,
{ text: getText(value), action: value })))
._bgSelectAria(value === that.rowCount)
._bgSelectAria(value.toString() === that.rowCount.toString())
.on("click" + namespace, menuItemSelector, function (e)
{
e.preventDefault();

var $this = $(this),
newRowCount = $this.data("action");
localStorage.setItem('rowCount[' + that.uid + ']', newRowCount);
if (newRowCount !== that.rowCount)
{
// todo: sophisticated solution needed for calculating which page is selected
Expand Down Expand Up @@ -833,11 +841,16 @@ function setTableHeaderSortDirection(element)
{
element.parents("tr").first().find(iconSelector).removeClass(css.iconDown + " " + css.iconUp);
this.sortDictionary = {};
for (var i = 0; i < this.columns.length; i++)
{
localStorage.removeItem('sortColumns[' + this.uid + '][' + this.columns[i].id + ']');
}
}

if (sortOrder && sortOrder === "asc")
{
this.sortDictionary[columnId] = "desc";
localStorage.setItem('sortColumns[' + this.uid + '][' + columnId + ']', "desc");
icon.removeClass(css.iconUp).addClass(css.iconDown);
}
else if (sortOrder && sortOrder === "desc")
Expand All @@ -853,17 +866,20 @@ function setTableHeaderSortDirection(element)
}
}
this.sortDictionary = newSort;
localStorage.removeItem('sortColumns[' + this.uid + '][' + columnId + ']');
icon.removeClass(css.iconDown);
}
else
{
this.sortDictionary[columnId] = "asc";
localStorage.setItem('sortColumns[' + this.uid + '][' + columnId + ']', "asc");
icon.removeClass(css.iconDown).addClass(css.iconUp);
}
}
else
{
this.sortDictionary[columnId] = "asc";
localStorage.setItem('sortColumns[' + this.uid + '][' + columnId + ']', "asc");
icon.addClass(css.iconUp);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var Grid = function(element, options)
this.header = null;
this.footer = null;
this.xqr = null;
this.uid = window.location.pathname + "#" + this.element.attr('id');

// todo: implement cache
};
Expand Down