diff --git a/bower.json b/bower.json index 92e66c5a..b31b36fc 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "jsgrid", - "version": "1.5.2", + "version": "1.5.3", "main": [ "dist/jsgrid.js", "dist/jsgrid.css", diff --git a/dist/jsgrid-theme.css b/dist/jsgrid-theme.css index 0c992862..ebc78552 100644 --- a/dist/jsgrid-theme.css +++ b/dist/jsgrid-theme.css @@ -1,5 +1,5 @@ /* - * jsGrid v1.5.2 (http://js-grid.com) + * jsGrid v1.5.3 (http://js-grid.com) * (c) 2016 Artem Tabalin * Licensed under MIT (https://github.com/tabalinas/jsgrid/blob/master/LICENSE) */ diff --git a/dist/jsgrid-theme.min.css b/dist/jsgrid-theme.min.css index f09f4725..f369d7ee 100644 --- a/dist/jsgrid-theme.min.css +++ b/dist/jsgrid-theme.min.css @@ -1,5 +1,5 @@ /* - * jsGrid v1.5.2 (http://js-grid.com) + * jsGrid v1.5.3 (http://js-grid.com) * (c) 2016 Artem Tabalin * Licensed under MIT (https://github.com/tabalinas/jsgrid/blob/master/LICENSE) */ diff --git a/dist/jsgrid.css b/dist/jsgrid.css index 56128ddb..a59154fb 100644 --- a/dist/jsgrid.css +++ b/dist/jsgrid.css @@ -1,5 +1,5 @@ /* - * jsGrid v1.5.2 (http://js-grid.com) + * jsGrid v1.5.3 (http://js-grid.com) * (c) 2016 Artem Tabalin * Licensed under MIT (https://github.com/tabalinas/jsgrid/blob/master/LICENSE) */ diff --git a/dist/jsgrid.js b/dist/jsgrid.js index 81d8c370..922bcdf4 100644 --- a/dist/jsgrid.js +++ b/dist/jsgrid.js @@ -1,5 +1,5 @@ /* - * jsGrid v1.5.2 (http://js-grid.com) + * jsGrid v1.5.3 (http://js-grid.com) * (c) 2016 Artem Tabalin * Licensed under MIT (https://github.com/tabalinas/jsgrid/blob/master/LICENSE) */ @@ -22,8 +22,6 @@ PAGE_INDEX_PLACEHOLDER = "{pageIndex}", PAGE_COUNT_PLACEHOLDER = "{pageCount}", ITEM_COUNT_PLACEHOLDER = "{itemCount}", - ITEM_INDEX_FROM_PLACEHOLDER = "{itemIndexFrom}", - ITEM_INDEX_TO_PLACEHOLDER = "{itemIndexTo}", EMPTY_HREF = "javascript:void(0);"; @@ -823,8 +821,6 @@ var pageIndex = this.pageIndex, pageCount = this._pagesCount(), itemCount = this._itemsCount(), - itemIndexFrom = ((this.pageIndex - 1) * this.pageSize + 1), - itemIndexTo = Math.min((this.pageIndex * this.pageSize), itemCount), pagerParts = this.pagerFormat.split(" "); return $.map(pagerParts, $.proxy(function(pagerPart) { @@ -846,10 +842,6 @@ result = pageCount; } else if(pagerPart === ITEM_COUNT_PLACEHOLDER) { result = itemCount; - } else if (pagerPart === ITEM_INDEX_FROM_PLACEHOLDER) { - result = itemIndexFrom; - } else if (pagerPart === ITEM_INDEX_TO_PLACEHOLDER) { - result = itemIndexTo; } return $.isArray(result) ? result.concat([" "]) : [result, " "]; @@ -915,20 +907,23 @@ }, _refreshWidth: function() { + var width = (this.width === "auto") ? this._getAutoWidth() : this.width; + + this._container.width(width); + }, + + _getAutoWidth: function() { var $headerGrid = this._headerGrid, - $bodyGrid = this._bodyGrid, - width = this.width; + $header = this._header; - if(width === "auto") { - $headerGrid.width("auto"); - width = $headerGrid.outerWidth(); - } + $headerGrid.width("auto"); + + var contentWidth = $headerGrid.outerWidth(); + var borderWidth = $header.outerWidth() - $header.innerWidth(); $headerGrid.width(""); - $bodyGrid.width(""); - this._container.width(width); - width = $headerGrid.outerWidth(); - $bodyGrid.width(width); + + return contentWidth + borderWidth; }, _scrollBarWidth: (function() { @@ -1166,14 +1161,13 @@ }; this._eachField(function(field) { - if(!field.validate) + if(!field.validate || + ($row === this._insertRow && !field.inserting) || + ($row === this._getEditRow() && !field.editing)) return; var fieldValue = this._getItemFieldValue(item, field); - if(fieldValue === undefined) - return; - var errors = this._validation.validate($.extend({ value: fieldValue, rules: field.validate @@ -1260,7 +1254,7 @@ _createEditRow: function(item) { if($.isFunction(this.editRowRenderer)) { - return $(this.renderTemplate(field.editRowRenderer, field, { item: item, itemIndex: this._itemIndex(item) })); + return $(this.renderTemplate(this.editRowRenderer, this, { item: item, itemIndex: this._itemIndex(item) })); } var $result = $("
",c,"headercss",this.headerCellClass).append(this.renderTemplate(c.headerTemplate,c)).appendTo(a);this.sorting&&c.sorting&&e.addClass(this.sortableClass).on("click",b.proxy(function(){this.sort(d)},this))}),a},_prepareCell:function(a,c,d,e){return b(a).css("width",c.width).addClass(e||this.cellClass).addClass(d&&c[d]||c.css).addClass(c.align?"jsgrid-align-"+c.align:"")},_createFilterRow:function(){if(b.isFunction(this.filterRowRenderer))return b(this.renderTemplate(this.filterRowRenderer,this));var a=b(" |
---|
",b,"filtercss").append(this.renderTemplate(b.filterTemplate,b)).appendTo(a)}),a},_createInsertRow:function(){if(b.isFunction(this.insertRowRenderer))return b(this.renderTemplate(this.insertRowRenderer,this));var a=b(" |
",b,"insertcss").append(this.renderTemplate(b.insertTemplate,b)).appendTo(a)}),a},_callEventHandler:function(a,c){return a.call(this,b.extend(c,{grid:this})),c},reset:function(){return this._resetSorting(),this._resetPager(),this._loadStrategy.reset()},_resetPager:function(){this._firstDisplayingPage=1,this._setPage(1)},_resetSorting:function(){this._sortField=null,this._sortOrder=i,this._clearSortingCss()},refresh:function(){this._callEventHandler(this.onRefreshing),this.cancelEdit(),this._refreshHeading(),this._refreshFiltering(),this._refreshInserting(),this._refreshContent(),this._refreshPager(),this._refreshSize(),this._callEventHandler(this.onRefreshed)},_refreshHeading:function(){this._headerRow.toggle(this.heading)},_refreshFiltering:function(){this._filterRow.toggle(this.filtering)},_refreshInserting:function(){this._insertRow.toggle(this.inserting)},_refreshContent:function(){var a=this._content;if(a.empty(),!this.data.length)return a.append(this._createNoDataRow()),this;for(var b=this._loadStrategy.firstDisplayIndex(),c=this._loadStrategy.lastDisplayIndex(),d=b;c>d;d++){var e=this.data[d];a.append(this._createRow(e,d))}},_createNoDataRow:function(){var a=0;return this._eachField(function(){a++}),b(" |
").addClass(this.cellClass).attr("colspan",a).append(this.renderTemplate(this.noDataContent,this)))},_createRow:function(a,c){var d;return b.isFunction(this.rowRenderer)?d=this.renderTemplate(this.rowRenderer,this,{item:a,itemIndex:c}):(d=b(" |
").append(this.renderTemplate(c.itemTemplate||e,c,f)),this._prepareCell(d,c)},_getItemFieldValue:function(a,b){for(var c=b.name.split("."),d=a[c.shift()];d&&c.length;)d=d[c.shift()];return d},_setItemFieldValue:function(a,b,c){for(var d=b.name.split("."),e=a,f=d[0];e&&d.length;)a=e,f=d.shift(),e=a[f];if(!e)for(;d.length;)a=a[f]={},f=d.shift();a[f]=c},sort:function(a,c){return b.isPlainObject(a)&&(c=a.order,a=a.field),this._clearSortingCss(),this._setSortingParams(a,c),this._setSortingCss(),this._loadStrategy.sort()},_clearSortingCss:function(){this._headerRow.find("th").removeClass(this.sortAscClass).removeClass(this.sortDescClass)},_setSortingParams:function(a,b){a=this._normalizeField(a),b=b||(this._sortField===a?this._reversedSortOrder(this._sortOrder):i),this._sortField=a,this._sortOrder=b},_normalizeField:function(a){return b.isNumeric(a)?this.fields[a]:"string"==typeof a?b.grep(this.fields,function(b){return b.name===a})[0]:a},_reversedSortOrder:function(a){return a===i?j:i},_setSortingCss:function(){var a=this._visibleFieldIndex(this._sortField);this._headerRow.find("th").eq(a).addClass(this._sortOrder===i?this.sortAscClass:this.sortDescClass)},_visibleFieldIndex:function(a){return b.inArray(a,b.grep(this.fields,function(a){return a.visible}))},_sortData:function(){var a=this._sortFactor(),b=this._sortField;b&&this.data.sort(function(c,d){return a*b.sortingFunc(c[b.name],d[b.name])})},_sortFactor:function(){return this._sortOrder===i?1:-1},_itemsCount:function(){return this._loadStrategy.itemsCount()},_pagesCount:function(){var a=this._itemsCount(),b=this.pageSize;return Math.floor(a/b)+(a%b?1:0)},_refreshPager:function(){var a=this._pagerContainer;a.empty(),this.paging&&a.append(this._createPager());var b=this.paging&&this._pagesCount()>1;a.toggle(b)},_createPager:function(){var a;return a=b.isFunction(this.pagerRenderer)?b(this.pagerRenderer({pageIndex:this.pageIndex,pageCount:this._pagesCount()})):b(" |