diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4c35228..26279a2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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.
diff --git a/bower.json b/bower.json
index 253e8d8..8163658 100644
--- a/bower.json
+++ b/bower.json
@@ -13,7 +13,7 @@
"accessibility",
"bootstrap"
],
- "version": "1.3.5",
+ "version": "1.4.0",
"authors": [
{
"name": "Rafael Staib",
diff --git a/dist/jQuery.Bootgrid.1.3.5.nupkg b/dist/jQuery.Bootgrid.1.3.5.nupkg
deleted file mode 100644
index f957c2e..0000000
Binary files a/dist/jQuery.Bootgrid.1.3.5.nupkg and /dev/null differ
diff --git a/dist/jquery.bootgrid-1.3.5.zip b/dist/jquery.bootgrid-1.3.5.zip
deleted file mode 100644
index 2a40ec9..0000000
Binary files a/dist/jquery.bootgrid-1.3.5.zip and /dev/null differ
diff --git a/dist/jquery.bootgrid-1.4.0.zip b/dist/jquery.bootgrid-1.4.0.zip
new file mode 100644
index 0000000..7f1c63d
Binary files /dev/null and b/dist/jquery.bootgrid-1.4.0.zip differ
diff --git a/dist/jquery.bootgrid.css b/dist/jquery.bootgrid.css
index cb38fd5..18111da 100644
--- a/dist/jquery.bootgrid.css
+++ b/dist/jquery.bootgrid.css
@@ -1,6 +1,6 @@
/*!
- * jQuery Bootgrid v1.3.5 - 03/11/2019
- * Copyright © 2014-2015 Rafael J. Staib; Copyright © 2018-2019 Deciso B.V. (http://www.jquery-bootgrid.com)
+ * 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.
*/
.bootgrid-header,
@@ -18,12 +18,14 @@
vertical-align: middle;
width: 180px;
}
-.bootgrid-header .search .glyphicon,
-.bootgrid-footer .search .glyphicon {
+.bootgrid-header .search .fa-solid,
+.bootgrid-footer .search .fa-solid {
top: 0;
}
.bootgrid-header .search .fa,
-.bootgrid-footer .search .fa {
+.bootgrid-header .search .fa-solid,
+.bootgrid-footer .search .fa,
+.bootgrid-footer .search .fa-solid {
display: table-cell;
}
.bootgrid-header .search.search-field::-ms-clear,
diff --git a/dist/jquery.bootgrid.fa.js b/dist/jquery.bootgrid.fa.js
index 62a75f5..2af272b 100644
--- a/dist/jquery.bootgrid.fa.js
+++ b/dist/jquery.bootgrid.fa.js
@@ -1,6 +1,6 @@
/*!
- * jQuery Bootgrid v1.3.5 - 03/11/2019
- * Copyright © 2014-2015 Rafael J. Staib; Copyright © 2018-2019 Deciso B.V. (http://www.jquery-bootgrid.com)
+ * 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.
*/
;(function ($, window, undefined)
diff --git a/dist/jquery.bootgrid.js b/dist/jquery.bootgrid.js
index 3b5faed..5b3769d 100644
--- a/dist/jquery.bootgrid.js
+++ b/dist/jquery.bootgrid.js
@@ -1,6 +1,6 @@
/*!
- * jQuery Bootgrid v1.3.5 - 03/11/2019
- * Copyright © 2014-2015 Rafael J. Staib; Copyright © 2018-2019 Deciso B.V. (http://www.jquery-bootgrid.com)
+ * 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.
*/
;(function ($, window, undefined)
@@ -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);
@@ -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,
@@ -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
@@ -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);
@@ -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
@@ -720,12 +728,15 @@ function renderSearchField()
var that = this,
tpl = this.options.templates,
timer = null, // fast keyup detection
- currentValue = "",
+ currentValue = this.searchPhrase,
searchFieldSelector = getCssSelector(css.searchField),
search = $(tpl.search.resolve(getParams.call(this))),
searchField = (search.is(searchFieldSelector)) ? search :
search.find(searchFieldSelector);
+ // populate search field if initial search phrase provided
+ $(searchField).val(currentValue);
+
searchField.on("keyup" + namespace, function (e)
{
e.stopPropagation();
@@ -843,11 +854,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")
@@ -863,17 +879,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);
}
}
@@ -984,7 +1003,7 @@ var Grid = function(element, options)
this.converter = null; // The converter for the column that is marked as identifier
this.rowCount = ($.isArray(rowCount)) ? rowCount[0] : rowCount;
this.rows = [];
- this.searchPhrase = "";
+ this.searchPhrase = this.options.initialSearchPhrase || "";
this.selectedRows = [];
this.sortDictionary = {};
this.total = 0;
@@ -997,6 +1016,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
};
@@ -1219,10 +1239,13 @@ Grid.defaults = {
datetime: {
// convert datetime type fields from unix timestamp to readable format
from: function (value) {
- return moment(parseInt(value)*1000);
+ return value ? moment(parseInt(value)*1000) : "";
},
to: function (value) {
- return value.format("lll");
+ if (!moment.isMoment(value)) {
+ value = moment(parseInt(value)*1000);
+ }
+ return value ? value.format("lll") : "";
}
},
memsize: {
@@ -1446,9 +1469,14 @@ Grid.prototype.append = function(rows)
var appendedRows = [];
for (var i = 0; i < rows.length; i++)
{
- if (appendRow.call(this, rows[i]))
+ var row = rows[i];
+ for (var j = 0; j < this.columns.length; j++) {
+ var column = this.columns[j];
+ row[column.id] = column.converter.from(row[column.id]);
+ }
+ if (appendRow.call(this, row))
{
- appendedRows.push(rows[i]);
+ appendedRows.push(row);
}
}
sortRows.call(this);
diff --git a/dist/jquery.bootgrid.min.css b/dist/jquery.bootgrid.min.css
index 6084ecd..706ed21 100644
--- a/dist/jquery.bootgrid.min.css
+++ b/dist/jquery.bootgrid.min.css
@@ -1,5 +1,5 @@
/*!
- * jQuery Bootgrid v1.3.5 - 03/11/2019
- * Copyright © 2014-2015 Rafael J. Staib; Copyright © 2018-2019 Deciso B.V. (http://www.jquery-bootgrid.com)
+ * 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.
*/.bootgrid-footer,.bootgrid-header{margin:15px 0}.bootgrid-footer a,.bootgrid-header a{outline:0}.bootgrid-footer .search,.bootgrid-header .search{display:inline-block;margin:0 20px 0 0;vertical-align:middle;width:180px}.bootgrid-footer .search .glyphicon,.bootgrid-header .search .glyphicon{top:0}.bootgrid-footer .search .fa,.bootgrid-header .search .fa{display:table-cell}.bootgrid-footer .search .search-field::-ms-clear,.bootgrid-footer .search.search-field::-ms-clear,.bootgrid-header .search .search-field::-ms-clear,.bootgrid-header .search.search-field::-ms-clear{display:none}.bootgrid-footer .pagination,.bootgrid-header .pagination{margin:0!important}.bootgrid-footer .infoBar,.bootgrid-header .actionBar{text-align:right}.bootgrid-footer .infoBar .btn-group>.btn-group .dropdown-menu,.bootgrid-header .actionBar .btn-group>.btn-group .dropdown-menu{text-align:left}.bootgrid-footer .infoBar .btn-group>.btn-group .dropdown-menu .dropdown-item,.bootgrid-header .actionBar .btn-group>.btn-group .dropdown-menu .dropdown-item{cursor:pointer;display:block;margin:0;padding:3px 20px;white-space:nowrap}.bootgrid-footer .infoBar .btn-group>.btn-group .dropdown-menu .dropdown-item:focus,.bootgrid-footer .infoBar .btn-group>.btn-group .dropdown-menu .dropdown-item:hover,.bootgrid-header .actionBar .btn-group>.btn-group .dropdown-menu .dropdown-item:focus,.bootgrid-header .actionBar .btn-group>.btn-group .dropdown-menu .dropdown-item:hover{color:#262626;text-decoration:none;background-color:#f5f5f5}.bootgrid-footer .infoBar .btn-group>.btn-group .dropdown-menu .dropdown-item .dropdown-item-checkbox,.bootgrid-footer .infoBar .btn-group>.btn-group .dropdown-menu .dropdown-item.dropdown-item-checkbox,.bootgrid-header .actionBar .btn-group>.btn-group .dropdown-menu .dropdown-item .dropdown-item-checkbox,.bootgrid-header .actionBar .btn-group>.btn-group .dropdown-menu .dropdown-item.dropdown-item-checkbox{margin:0 2px 4px 0;vertical-align:middle}.bootgrid-footer .infoBar .btn-group>.btn-group .dropdown-menu .dropdown-item.disabled,.bootgrid-header .actionBar .btn-group>.btn-group .dropdown-menu .dropdown-item.disabled{cursor:not-allowed}.bootgrid-table{table-layout:fixed}.bootgrid-table a{outline:0}.bootgrid-table th>.column-header-anchor{color:#333;cursor:not-allowed;display:block;position:relative;text-decoration:none}.bootgrid-table th>.column-header-anchor.sortable{cursor:pointer}.bootgrid-table th>.column-header-anchor>.text{display:block;margin:0 16px 0 0;overflow:hidden;-ms-text-overflow:ellipsis;-o-text-overflow:ellipsis;text-overflow:ellipsis;white-space:nowrap}.bootgrid-table th>.column-header-anchor>.icon{display:block;position:absolute;right:0;top:2px}.bootgrid-table th:active,.bootgrid-table th:hover{background:#fafafa}.bootgrid-table td{overflow:hidden;-ms-text-overflow:ellipsis;-o-text-overflow:ellipsis;text-overflow:ellipsis;white-space:nowrap}.bootgrid-table td.loading,.bootgrid-table td.no-results{background:#fff;text-align:center}.bootgrid-table td.select-cell,.bootgrid-table th.select-cell{text-align:center;width:30px}.bootgrid-table td.select-cell .select-box,.bootgrid-table th.select-cell .select-box{margin:0;outline:0}.table-responsive .bootgrid-table{table-layout:inherit!important}.table-responsive .bootgrid-table th>.column-header-anchor>.text{overflow:inherit!important;-ms-text-overflow:inherit!important;-o-text-overflow:inherit!important;text-overflow:inherit!important;white-space:inherit!important}.table-responsive .bootgrid-table td{overflow:inherit!important;-ms-text-overflow:inherit!important;-o-text-overflow:inherit!important;text-overflow:inherit!important;white-space:inherit!important}
\ No newline at end of file
diff --git a/dist/jquery.bootgrid.min.js b/dist/jquery.bootgrid.min.js
index 8ca9d69..21dd490 100644
--- a/dist/jquery.bootgrid.min.js
+++ b/dist/jquery.bootgrid.min.js
@@ -1 +1 @@
-!function(p,h,t){"use strict";var f=".rs.jquery.bootgrid";function n(e){var i=this;return!this.rows.contains(function(t){return i.identifier&&t[i.identifier]===e[i.identifier]})&&(this.rows.push(e),!0)}function g(t){var e=this.footer?this.footer.find(t):p(),i=this.header?this.header.find(t):p();return p.merge(e,i)}function v(t){return t?p.extend({},this.cachedParams,{ctx:t}):this.cachedParams}function m(t){return"."+p.trim(t).replace(/\s+/gm,".")}function l(){this.element.trigger("initialize"+f),function(){var s=this,t=this.element.find("thead > tr").first(),n=!1;t.children().each(function(){var t=p(this),e=t.data(),i={id:e.columnId,identifier:null==s.identifier&&e.identifier||!1,converter:s.options.converters[e.converter||e.type]||s.options.converters.string,text:t.html(),align:e.align||"left",headerAlign:e.headerAlign||"left",cssClass:e.cssClass||"",headerCssClass:e.headerCssClass||"",formatter:s.options.formatters[e.formatter]||null,order:n||"asc"!==e.order&&"desc"!==e.order?null:e.order,searchable:!(!1===e.searchable),sortable:!(!1===e.sortable),visible:!(!1===e.visible),visibleInSelection:!(!1===e.visibleInSelection),width:p.isNumeric(e.width)?e.width+"px":"string"==typeof e.width?e.width:null};s.columns.push(i),null!=i.order&&(s.sortDictionary[i.id]=i.order),i.identifier&&(s.identifier=i.id,s.converter=i.converter),s.options.multiSort||null===i.order||(n=!0)})}.call(this),this.selection=this.options.selection&&null!=this.identifier,function(){if(!this.options.ajax){var e=this,t=this.element.find("tbody > tr");t.each(function(){var t=p(this),i=t.children("td"),s={};p.each(e.columns,function(t,e){s[e.id]=e.converter.from(i.eq(t).text())}),n.call(e,s)}),a.call(this,this.rows.length),o.call(this)}}.call(this),function(){var t=this.options.templates,e=this.element.parent().hasClass(this.options.css.responsiveTable)?this.element.parent():this.element;this.element.addClass(this.options.css.table),0===this.element.children("tbody").length&&this.element.append(t.body);1&this.options.navigation&&(this.header=p(t.header.resolve(v.call(this,{id:this.element._bgId()+"-header"}))),e.before(this.header));2&this.options.navigation&&(this.footer=p(t.footer.resolve(v.call(this,{id:this.element._bgId()+"-footer"}))),e.after(this.footer))}.call(this),x.call(this),function(){if(0!==this.options.navigation){var t=this.options.css,e=m(t.search),i=g.call(this,e);if(0=s.options.searchSettings.characters)&&(h.clearTimeout(o),o=h.setTimeout(function(){y.call(s,e)},s.options.searchSettings.delay)))}),C.call(this,i,a)}}}.call(this),function(){if(0!==this.options.navigation){var t=this.options.css,e=m(t.actions),i=g.call(this,e);if(0 tr").on("click"+f,"> tr",function(t){t.stopPropagation();var e=p(this),i=null==n.identifier?e.data("row-id"):n.converter.from(e.data("row-id")+""),s=null==n.identifier?n.currentRows[i]:n.currentRows.first(function(t){return t[n.identifier]===i});n.selection&&n.options.rowSelect&&(e.hasClass(n.options.css.selected)?n.deselect([i]):n.select([i])),n.element.trigger("click"+f,[n.columns,s])})}.call(this,e)}else b.call(this)}.call(n,t),function(){if(0!==this.options.navigation){var t=m(this.options.css.infos),e=g.call(this,t);if(0this.total?this.total:i,start:0===this.total?0:i-this.rowCount+1,total:this.total})));C.call(this,e,s)}}}.call(n),function(){if(0!==this.options.navigation){var t=m(this.options.css.pagination),e=g.call(this,t)._bgShowAria(-1!==this.rowCount);if(-1!==this.rowCount&&0=this.options.padding?Math.max(l,1):Math.max(l-this.options.padding+r,1),c=2*this.options.padding+1,h=c<=n?c:n;w.call(this,o,"first","«","first")._bgEnableAria(1 td").first(),n=r.element.height()-e.height()-(s.height()+20),o=r.columns.where(u).length;r.selection&&(o+=1),i.html(t.loading.resolve(v.call(r,{columns:o}))),-1!==r.rowCount&&0 td").css("padding","20px 0 "+n+"px")}},250)}.call(this),this.options.ajax){var t=function(){var t={current:this.current,rowCount:this.rowCount,sort:this.sortDictionary,searchPhrase:this.searchPhrase},e=this.options.post;return e=p.isFunction(e)?e():e,this.options.requestHandler(p.extend(!0,t,e))}.call(this),i=function(){var t=this.options.url;return p.isFunction(t)?t():t}.call(this);if(null==i||"string"!=typeof i||0===i.length)throw new Error("Url setting must be a none empty string or a function that returns one.");this.xqr&&this.xqr.abort();var s={url:i,data:t,success:function(t){n.xqr=null,"string"==typeof t&&(t=p.parseJSON(t)),t=n.options.responseHandler(t),n.current=t.current,e(t.rows,t.total)},error:function(t,e,i){n.xqr=null,"abort"!==e&&(b.call(n),n.element._bgBusyAria(!1).trigger("loaded"+f))}};s=p.extend(this.options.ajaxSettings,s),this.xqr=p.ajax(s)}else{var o=0 tr"),a=this.options.css,c=this.options.templates,h="",u=this.options.sorting;if(this.selection){var e=this.options.multiSelect?c.select.resolve(v.call(l,{type:"checkbox",value:"all"})):"";h+=c.rawHeaderCell.resolve(v.call(l,{content:e,css:a.selectCell}))}if(p.each(this.columns,function(t,e){if(e.visible){var i=l.sortDictionary[e.id],s=u&&i&&"asc"===i?a.iconUp:u&&i&&"desc"===i?a.iconDown:"",n=c.icon.resolve(v.call(l,{iconCss:s})),o=e.headerAlign,r=0i[o.id]?r(1):e[o.id]n?t(e,i,n):0})}}var c=function(t,e){this.element=p(t),this.origin=this.element.clone(),this.options=p.extend(!0,{},c.defaults,this.element.data(),e);var i=this.options.rowCount=this.element.data().rowCount||e.rowCount||this.options.rowCount;this.columns=[],this.current=1,this.currentRows=[],this.identifier=null,this.selection=!1,this.converter=null,this.rowCount=p.isArray(i)?i[0]:i,this.rows=[],this.searchPhrase="",this.selectedRows=[],this.sortDictionary={},this.total=0,this.totalPages=0,this.cachedParams={lbl:this.options.labels,css:this.options.css,ctx:{}},this.header=null,this.footer=null,this.xqr=null};if(c.defaults={navigation:3,padding:2,columnSelection:!0,rowCount:[10,25,50,-1],selection:!1,multiSelect:!1,rowSelect:!1,keepSelection:!1,highlightRows:!1,sorting:!0,multiSort:!1,searchSettings:{delay:250,characters:1},ajax:!1,ajaxSettings:{method:"POST"},post:{},url:"",caseSensitive:!0,requestHandler:function(t){return t},responseHandler:function(t){return t},converters:{numeric:{from:function(t){return+t},to:function(t){return void 0===t?"":t+""}},string:{from:function(t){return t},to:function(t){return t}},datetime:{from:function(t){return moment(1e3*parseInt(t))},to:function(t){return t.format("lll")}},memsize:{from:function(t){for(var e=["","K","M","G","T","P","E","Z","Y"],i=parseInt(t),s=t.slice(-1).toUpperCase(),n=e.length-1;0<=n;n--)if(s===e[n]){i*=Math.pow(1024,n);break}return i},to:function(t){for(var e=["","K","M","G","T","P","E","Z","Y"],i=e.length-1;0<=i;i--)if(t>=5*Math.pow(1024,i))return parseInt(t/Math.pow(1024,i))+e[i];return parseInt(t)+""}},notprefixable:{to:function(t){return t.not?' '+t.val:t.val}}},css:{actions:"actions btn-group",center:"text-center",columnHeaderAnchor:"column-header-anchor",columnHeaderText:"text",dropDownItem:"dropdown-item",dropDownItemButton:"dropdown-item-button",dropDownItemCheckbox:"dropdown-item-checkbox",dropDownMenu:"dropdown btn-group",dropDownMenuItems:"dropdown-menu pull-right",dropDownMenuText:"dropdown-text",footer:"bootgrid-footer container-fluid",header:"bootgrid-header container-fluid",icon:"icon glyphicon",iconColumns:"glyphicon-th-list",iconDown:"glyphicon-chevron-down",iconRefresh:"glyphicon-refresh",iconSearch:"glyphicon-search",iconUp:"glyphicon-chevron-up",infos:"infos",left:"text-left",pagination:"pagination",paginationButton:"button",responsiveTable:"table-responsive",right:"text-right",search:"search form-group",searchField:"search-field form-control",selectBox:"select-box",selectCell:"select-cell",selected:"active",sortable:"sortable",table:"bootgrid-table table"},formatters:{},labels:{all:"All",infos:"Showing {{ctx.start}} to {{ctx.end}} of {{ctx.total}} entries",loading:"Loading...",noResults:"No results found!",refresh:"Refresh",search:"Search"},statusMapping:{0:"success",1:"info",2:"warning",3:"danger"},templates:{actionButton:'',actionDropDown:'',actionDropDownItem:'{{ctx.text}}',actionDropDownCheckboxItem:'',actions:'',body:"",cell:'| {{ctx.content}} | ',footer:'',header:'',headerCell:'{{ctx.column.text}}{{ctx.icon}} | ',icon:'',infos:'{{lbl.infos}}
',loading:'| {{lbl.loading}} |
',noResults:'| {{lbl.noResults}} |
',pagination:'',paginationItem:'',rawHeaderCell:'{{ctx.content}} | ',row:"{{ctx.cells}}
",search:'',select:''}},c.prototype.append=function(t){if(this.options.ajax);else{for(var e=[],i=0;i=this.currentRows.length;for(i=0;!this.options.keepSelection&&o&&i tr "+n+":checked").trigger("click"+f),i=0;i tr[data-row-id="'+this.selectedRows[i]+'"]').addClass(this.options.css.selected)._bgAria("selected","true").find(n).prop("checked",!0);this.element.trigger("selected"+f,[s])}}return this},c.prototype.deselect=function(t){if(this.selection){t=t||this.currentRows.propValues(this.identifier);for(var e,i,s,n=[];0 tr[data-row-id="'+n[i][this.identifier]+'"]').removeClass(this.options.css.selected)._bgAria("selected","false").find(o).prop("checked",!1);this.element.trigger("deselected"+f,[n])}}return this},c.prototype.sort=function(t){var e=t?p.extend({},t):{};return e===this.sortDictionary||(this.sortDictionary=e,x.call(this),o.call(this),d.call(this)),this},c.prototype.getColumnSettings=function(){return p.merge([],this.columns)},c.prototype.getCurrentPage=function(){return this.current},c.prototype.getCurrentRows=function(){return p.merge([],this.currentRows)},c.prototype.getRowCount=function(){return this.rowCount},c.prototype.getSearchPhrase=function(){return this.searchPhrase},c.prototype.getSelectedRows=function(){return p.merge([],this.selectedRows)},c.prototype.getSortDictionary=function(){return p.extend({},this.sortDictionary)},c.prototype.getTotalPageCount=function(){return this.totalPages},c.prototype.getTotalRowCount=function(){return this.total},p.fn.extend({_bgAria:function(t,e){return e?this.attr("aria-"+t,e):this.attr("aria-"+t)},_bgBusyAria:function(t){return null==t||t?this._bgAria("busy","true"):this._bgAria("busy","false")},_bgRemoveAria:function(t){return this.removeAttr("aria-"+t)},_bgEnableAria:function(t){return null==t||t?this.removeClass("disabled")._bgAria("disabled","false"):this.addClass("disabled")._bgAria("disabled","true")},_bgEnableField:function(t){return null==t||t?this.removeAttr("disabled"):this.attr("disabled","disable")},_bgShowAria:function(t){return null==t||t?this.show()._bgAria("hidden","false"):this.hide()._bgAria("hidden","true")},_bgSelectAria:function(t){return null==t||t?this.addClass("active")._bgAria("selected","true"):this.removeClass("active")._bgAria("selected","false")},_bgId:function(t){return t?this.attr("id",t):this.attr("id")}}),!String.prototype.resolve){var r={checked:function(t){return"boolean"==typeof t?t?'checked="checked"':"":t}};String.prototype.resolve=function(t,n){var o=this;return p.each(t,function(t,e){if(null!=e&&"function"!=typeof e)if("object"==typeof e){var i=n?p.extend([],n):[];i.push(t),o=o.resolve(e,i)+""}else{r&&r[t]&&"function"==typeof r[t]&&(e=r[t](e)),t=n?n.join(".")+"."+t:t;var s=new RegExp("\\{\\{"+t+"\\}\\}","gm");o=o.replace(s,e.replace?e.replace(/\$/gi,"$"):e)}}),o}}Array.prototype.first||(Array.prototype.first=function(t){for(var e=0;ei?this.length>s?this.slice(i,s):this.slice(i):[]}),Array.prototype.where||(Array.prototype.where=function(t){for(var e=[],i=0;i tr").first(),r=!1;t.children().each(function(){var t=p(this),e=t.data(),i=localStorage.getItem("visibleColumns["+n.uid+"]["+e.columnId+"]"),s=localStorage.getItem("sortColumns["+n.uid+"]["+e.columnId+"]"),o={id:e.columnId,identifier:null==n.identifier&&e.identifier||!1,converter:n.options.converters[e.converter||e.type]||n.options.converters.string,text:t.html(),align:e.align||"left",headerAlign:e.headerAlign||"left",cssClass:e.cssClass||"",headerCssClass:e.headerCssClass||"",formatter:n.options.formatters[e.formatter]||null,order:r?null:null===s?"asc"===e.order||"desc"===e.order?e.order:null:"asc"===s||"desc"===s?s:null,searchable:!(!1===e.searchable),sortable:!(!1===e.sortable),visible:null===i?!(!1===e.visible):"true"===i,visibleInSelection:!(!1===e.visibleInSelection),width:p.isNumeric(e.width)?e.width+"px":"string"==typeof e.width?e.width:null};n.columns.push(o),null!=o.order&&(n.sortDictionary[o.id]=o.order),o.identifier&&(n.identifier=o.id,n.converter=o.converter),n.options.multiSort||null===o.order||(r=!0)})}.call(this),this.selection=this.options.selection&&null!=this.identifier,this.rowCount=localStorage.getItem("rowCount["+this.uid+"]")||this.rowCount,function(){if(!this.options.ajax){var e=this,t=this.element.find("tbody > tr");t.each(function(){var t=p(this),i=t.children("td"),s={};p.each(e.columns,function(t,e){s[e.id]=e.converter.from(i.eq(t).text())}),r.call(e,s)}),a.call(this,this.rows.length),D.call(this)}}.call(this),function(){var t=this.options.templates,e=this.element.parent().hasClass(this.options.css.responsiveTable)?this.element.parent():this.element;this.element.addClass(this.options.css.table),0===this.element.children("tbody").length&&this.element.append(t.body);1&this.options.navigation&&(this.header=p(t.header.resolve(v.call(this,{id:this.element._bgId()+"-header"}))),e.before(this.header));2&this.options.navigation&&(this.footer=p(t.footer.resolve(v.call(this,{id:this.element._bgId()+"-footer"}))),e.after(this.footer))}.call(this),x.call(this),function(){if(0!==this.options.navigation){var t=this.options.css,e=m(t.search),i=g.call(this,e);if(0=s.options.searchSettings.characters)&&(h.clearTimeout(n),n=h.setTimeout(function(){y.call(s,e)},s.options.searchSettings.delay)))}),C.call(this,i,a)}}}.call(this),function(){if(0!==this.options.navigation){var t=this.options.css,e=m(t.actions),i=g.call(this,e);if(0 tr").on("click"+f,"> tr",function(t){t.stopPropagation();var e=p(this),i=null==o.identifier?e.data("row-id"):o.converter.from(e.data("row-id")+""),s=null==o.identifier?o.currentRows[i]:o.currentRows.first(function(t){return t[o.identifier]===i});o.selection&&o.options.rowSelect&&(e.hasClass(o.options.css.selected)?o.deselect([i]):o.select([i])),o.element.trigger("click"+f,[o.columns,s])})}.call(this,e)}else b.call(this)}.call(o,t),function(){if(0!==this.options.navigation){var t=m(this.options.css.infos),e=g.call(this,t);if(0this.total?this.total:i,start:0===this.total?0:i-this.rowCount+1,total:this.total})));C.call(this,e,s)}}}.call(o),function(){if(0!==this.options.navigation){var t=m(this.options.css.pagination),e=g.call(this,t)._bgShowAria(-1!==this.rowCount);if(-1!==this.rowCount&&0=this.options.padding?Math.max(l,1):Math.max(l-this.options.padding+r,1),c=2*this.options.padding+1,h=c<=o?c:o;w.call(this,n,"first","«","first")._bgEnableAria(1 td").first(),o=r.element.height()-e.height()-(s.height()+20),n=r.columns.where(u).length;r.selection&&(n+=1),i.html(t.loading.resolve(v.call(r,{columns:n}))),-1!==r.rowCount&&0 td").css("padding","20px 0 "+o+"px")}},250)}.call(this),this.options.ajax){var t=function(){var t={current:this.current,rowCount:this.rowCount,sort:this.sortDictionary,searchPhrase:this.searchPhrase},e=this.options.post;return e=p.isFunction(e)?e():e,this.options.requestHandler(p.extend(!0,t,e))}.call(this),i=function(){var t=this.options.url;return p.isFunction(t)?t():t}.call(this);if(null==i||"string"!=typeof i||0===i.length)throw new Error("Url setting must be a none empty string or a function that returns one.");this.xqr&&this.xqr.abort();var s={url:i,data:t,success:function(t){o.xqr=null,"string"==typeof t&&(t=p.parseJSON(t)),t=o.options.responseHandler(t),o.current=t.current,e(t.rows,t.total)},error:function(t,e,i){o.xqr=null,"abort"!==e&&(b.call(o),o.element._bgBusyAria(!1).trigger("loaded"+f))}};s=p.extend(this.options.ajaxSettings,s),this.xqr=p.ajax(s)}else{var n=0 tr"),a=this.options.css,c=this.options.templates,h="",u=this.options.sorting;if(this.selection){var e=this.options.multiSelect?c.select.resolve(v.call(l,{type:"checkbox",value:"all"})):"";h+=c.rawHeaderCell.resolve(v.call(l,{content:e,css:a.selectCell}))}if(p.each(this.columns,function(t,e){if(e.visible){var i=l.sortDictionary[e.id],s=u&&i&&"asc"===i?a.iconUp:u&&i&&"desc"===i?a.iconDown:"",o=c.icon.resolve(v.call(l,{iconCss:s})),n=e.headerAlign,r=0i[n.id]?r(1):e[n.id]o?t(e,i,o):0})}}var c=function(t,e){this.element=p(t),this.origin=this.element.clone(),this.options=p.extend(!0,{},c.defaults,this.element.data(),e);var i=this.options.rowCount=this.element.data().rowCount||e.rowCount||this.options.rowCount;this.columns=[],this.current=1,this.currentRows=[],this.identifier=null,this.selection=!1,this.converter=null,this.rowCount=p.isArray(i)?i[0]:i,this.rows=[],this.searchPhrase="",this.selectedRows=[],this.sortDictionary={},this.total=0,this.totalPages=0,this.cachedParams={lbl:this.options.labels,css:this.options.css,ctx:{}},this.header=null,this.footer=null,this.xqr=null,this.uid=h.location.pathname+"#"+this.element.attr("id")};if(c.defaults={navigation:3,padding:2,columnSelection:!0,rowCount:[10,25,50,-1],selection:!1,multiSelect:!1,rowSelect:!1,keepSelection:!1,highlightRows:!1,sorting:!0,multiSort:!1,searchSettings:{delay:250,characters:1},ajax:!1,ajaxSettings:{method:"POST"},post:{},url:"",caseSensitive:!0,requestHandler:function(t){return t},responseHandler:function(t){return t},converters:{numeric:{from:function(t){return+t},to:function(t){return void 0===t?"":t+""}},string:{from:function(t){return t},to:function(t){return t}},datetime:{from:function(t){return t?moment(1e3*parseInt(t)):""},to:function(t){return t?t.format("lll"):""}},memsize:{from:function(t){for(var e=["","K","M","G","T","P","E","Z","Y"],i=parseInt(t),s=t.slice(-1).toUpperCase(),o=e.length-1;0<=o;o--)if(s===e[o]){i*=Math.pow(1024,o);break}return i},to:function(t){for(var e=["","K","M","G","T","P","E","Z","Y"],i=e.length-1;0<=i;i--)if(t>=5*Math.pow(1024,i))return parseInt(t/Math.pow(1024,i))+e[i];return parseInt(t)+""}},notprefixable:{to:function(t){return t.not?' '+t.val:t.val}}},css:{actions:"actions btn-group",center:"text-center",columnHeaderAnchor:"column-header-anchor",columnHeaderText:"text",dropDownItem:"dropdown-item",dropDownItemButton:"dropdown-item-button",dropDownItemCheckbox:"dropdown-item-checkbox",dropDownMenu:"dropdown btn-group",dropDownMenuItems:"dropdown-menu pull-right",dropDownMenuText:"dropdown-text",footer:"bootgrid-footer container-fluid",header:"bootgrid-header container-fluid",icon:"icon glyphicon",iconColumns:"glyphicon-th-list",iconDown:"glyphicon-chevron-down",iconRefresh:"glyphicon-refresh",iconSearch:"glyphicon-search",iconUp:"glyphicon-chevron-up",infos:"infos",left:"text-left",pagination:"pagination",paginationButton:"button",responsiveTable:"table-responsive",right:"text-right",search:"search form-group",searchField:"search-field form-control",selectBox:"select-box",selectCell:"select-cell",selected:"active",sortable:"sortable",table:"bootgrid-table table"},formatters:{},labels:{all:"All",infos:"Showing {{ctx.start}} to {{ctx.end}} of {{ctx.total}} entries",loading:"Loading...",noResults:"No results found!",refresh:"Refresh",search:"Search"},statusMapping:{0:"success",1:"info",2:"warning",3:"danger"},templates:{actionButton:'',actionDropDown:'',actionDropDownItem:'{{ctx.text}}',actionDropDownCheckboxItem:'',actions:'',body:"",cell:'| {{ctx.content}} | ',footer:'',header:'',headerCell:'{{ctx.column.text}}{{ctx.icon}} | ',icon:'',infos:'{{lbl.infos}}
',loading:'| {{lbl.loading}} |
',noResults:'| {{lbl.noResults}} |
',pagination:'',paginationItem:'',rawHeaderCell:'{{ctx.content}} | ',row:"{{ctx.cells}}
",search:'',select:''}},c.prototype.append=function(t){if(this.options.ajax);else{for(var e=[],i=0;i=this.currentRows.length;for(i=0;!this.options.keepSelection&&n&&i tr "+o+":checked").trigger("click"+f),i=0;i tr[data-row-id="'+this.selectedRows[i]+'"]').addClass(this.options.css.selected)._bgAria("selected","true").find(o).prop("checked",!0);this.element.trigger("selected"+f,[s])}}return this},c.prototype.deselect=function(t){if(this.selection){t=t||this.currentRows.propValues(this.identifier);for(var e,i,s,o=[];0 tr[data-row-id="'+o[i][this.identifier]+'"]').removeClass(this.options.css.selected)._bgAria("selected","false").find(n).prop("checked",!1);this.element.trigger("deselected"+f,[o])}}return this},c.prototype.sort=function(t){var e=t?p.extend({},t):{};return e===this.sortDictionary||(this.sortDictionary=e,x.call(this),D.call(this),d.call(this)),this},c.prototype.getColumnSettings=function(){return p.merge([],this.columns)},c.prototype.getCurrentPage=function(){return this.current},c.prototype.getCurrentRows=function(){return p.merge([],this.currentRows)},c.prototype.getRowCount=function(){return this.rowCount},c.prototype.getSearchPhrase=function(){return this.searchPhrase},c.prototype.getSelectedRows=function(){return p.merge([],this.selectedRows)},c.prototype.getSortDictionary=function(){return p.extend({},this.sortDictionary)},c.prototype.getTotalPageCount=function(){return this.totalPages},c.prototype.getTotalRowCount=function(){return this.total},p.fn.extend({_bgAria:function(t,e){return e?this.attr("aria-"+t,e):this.attr("aria-"+t)},_bgBusyAria:function(t){return null==t||t?this._bgAria("busy","true"):this._bgAria("busy","false")},_bgRemoveAria:function(t){return this.removeAttr("aria-"+t)},_bgEnableAria:function(t){return null==t||t?this.removeClass("disabled")._bgAria("disabled","false"):this.addClass("disabled")._bgAria("disabled","true")},_bgEnableField:function(t){return null==t||t?this.removeAttr("disabled"):this.attr("disabled","disable")},_bgShowAria:function(t){return null==t||t?this.show()._bgAria("hidden","false"):this.hide()._bgAria("hidden","true")},_bgSelectAria:function(t){return null==t||t?this.addClass("active")._bgAria("selected","true"):this.removeClass("active")._bgAria("selected","false")},_bgId:function(t){return t?this.attr("id",t):this.attr("id")}}),!String.prototype.resolve){var S={checked:function(t){return"boolean"==typeof t?t?'checked="checked"':"":t}};String.prototype.resolve=function(t,o){var n=this;return p.each(t,function(t,e){if(null!=e&&"function"!=typeof e)if("object"==typeof e){var i=o?p.extend([],o):[];i.push(t),n=n.resolve(e,i)+""}else{S&&S[t]&&"function"==typeof S[t]&&(e=S[t](e)),t=o?o.join(".")+"."+t:t;var s=new RegExp("\\{\\{"+t+"\\}\\}","gm");n=n.replace(s,e.replace?e.replace(/\$/gi,"$"):e)}}),n}}Array.prototype.first||(Array.prototype.first=function(t){for(var e=0;ei?this.length>s?this.slice(i,s):this.slice(i):[]}),Array.prototype.where||(Array.prototype.where=function(t){for(var e=[],i=0;i 1;
$this.parents(itemsSelector).find(selector + ":has(" + checkboxSelector + ":checked)")
._bgEnableAria(enable).find(checkboxSelector)._bgEnableField(enable);
@@ -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
@@ -710,12 +718,15 @@ function renderSearchField()
var that = this,
tpl = this.options.templates,
timer = null, // fast keyup detection
- currentValue = "",
+ currentValue = this.searchPhrase,
searchFieldSelector = getCssSelector(css.searchField),
search = $(tpl.search.resolve(getParams.call(this))),
searchField = (search.is(searchFieldSelector)) ? search :
search.find(searchFieldSelector);
+ // populate search field if initial search phrase provided
+ $(searchField).val(currentValue);
+
searchField.on("keyup" + namespace, function (e)
{
e.stopPropagation();
@@ -833,11 +844,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")
@@ -853,17 +869,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);
}
}
diff --git a/src/public.js b/src/public.js
index 63579e6..62bd50a 100644
--- a/src/public.js
+++ b/src/public.js
@@ -25,7 +25,7 @@ var Grid = function(element, options)
this.converter = null; // The converter for the column that is marked as identifier
this.rowCount = ($.isArray(rowCount)) ? rowCount[0] : rowCount;
this.rows = [];
- this.searchPhrase = "";
+ this.searchPhrase = this.options.initialSearchPhrase || "";
this.selectedRows = [];
this.sortDictionary = {};
this.total = 0;
@@ -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
};
@@ -260,10 +261,13 @@ Grid.defaults = {
datetime: {
// convert datetime type fields from unix timestamp to readable format
from: function (value) {
- return moment(parseInt(value)*1000);
+ return value ? moment(parseInt(value)*1000) : "";
},
to: function (value) {
- return value.format("lll");
+ if (!moment.isMoment(value)) {
+ value = moment(parseInt(value)*1000);
+ }
+ return value ? value.format("lll") : "";
}
},
memsize: {
@@ -323,12 +327,12 @@ Grid.defaults = {
dropDownMenuText: "dropdown-text", // must be a unique class name or constellation of class names within the actionDropDown
footer: "bootgrid-footer container-fluid",
header: "bootgrid-header container-fluid",
- icon: "icon glyphicon",
- iconColumns: "glyphicon-th-list",
- iconDown: "glyphicon-chevron-down",
- iconRefresh: "glyphicon-refresh",
- iconSearch: "glyphicon-search",
- iconUp: "glyphicon-chevron-up",
+ icon: "icon fa-solid",
+ iconColumns: "fa-list",
+ iconDown: "fa-chevron-down",
+ iconRefresh: "fa-arrows-rotate",
+ iconSearch: "fa-magnifying-glass",
+ iconUp: "fa-chevron-up",
infos: "infos", // must be a unique class name or constellation of class names within the header and footer,
left: "text-left",
pagination: "pagination", // must be a unique class name or constellation of class names within the header and footer
@@ -487,9 +491,14 @@ Grid.prototype.append = function(rows)
var appendedRows = [];
for (var i = 0; i < rows.length; i++)
{
- if (appendRow.call(this, rows[i]))
+ var row = rows[i];
+ for (var j = 0; j < this.columns.length; j++) {
+ var column = this.columns[j];
+ row[column.id] = column.converter.from(row[column.id]);
+ }
+ if (appendRow.call(this, row))
{
- appendedRows.push(rows[i]);
+ appendedRows.push(row);
}
}
sortRows.call(this);