Permalink
Browse files

Core: Prevent grid from shrinking on refresh when with 'auto'

Fixes #307
1 parent 984c393 commit 398847812a78384ae6c84ae707cfa95b8e54dba5 @tabalinas committed Nov 3, 2016
Showing with 18 additions and 15 deletions.
  1. +5 −5 demos/odata-service.html
  2. +13 −10 src/jsgrid.core.js
@@ -35,7 +35,7 @@
$("#jsGrid").jsGrid({
height: "auto",
- width: "100%",
+ width: "auto",
sorting: true,
paging: false,
autoload: true,
@@ -54,14 +54,14 @@
}
},
fields: [
- { name: "Name", type: "text" },
- { name: "Description", type: "textarea", width: 150 },
- { name: "Rating", type: "number", width: 50, align: "center",
+ { name: "Name", type: "text", width: 100 },
+ { name: "Description", type: "textarea", width: 200 },
+ { name: "Rating", type: "number", width: 150, align: "center",
itemTemplate: function(value) {
return $("<div>").addClass("rating").append(Array(value + 1).join("&#9733;"));
}
},
- { name: "Price", type: "number", width: 50,
+ { name: "Price", type: "number", width: 100,
itemTemplate: function(value) {
return value.toFixed(2) + "$"; }
}
View
@@ -901,20 +901,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() {

0 comments on commit 3988478

Please sign in to comment.