From b550436143dea4eccd716ad0784e19ed98890b35 Mon Sep 17 00:00:00 2001 From: huer12 Date: Wed, 8 Jan 2014 10:02:26 +0100 Subject: [PATCH] Add bootstrap tab plugin and row selection plugin --- plugins/KoGridRowSelectionPlugin.js | 30 +++++++++++++++++++++++++++++ plugins/koGridBootstrapTabPlugin.js | 19 ++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 plugins/KoGridRowSelectionPlugin.js create mode 100644 plugins/koGridBootstrapTabPlugin.js diff --git a/plugins/KoGridRowSelectionPlugin.js b/plugins/KoGridRowSelectionPlugin.js new file mode 100644 index 00000000..a91117b0 --- /dev/null +++ b/plugins/KoGridRowSelectionPlugin.js @@ -0,0 +1,30 @@ + // use this plugin if you need to change the selection programmatically + var KoGridRowSelectionPlugin = (function () { + function KoGridRowSelectionPlugin(selectedItems) { + this.selectedItems = selectedItems; + } + KoGridRowSelectionPlugin.prototype.onGridInit = function (grid) { + var _this = this; + this._grid = grid; + + this.selectedItems.subscribe(function (newValues) { + if (_this._grid.$$selectionPhase == true) + return; + + for (var j = 0; j < newValues.length; j++) { + var newValue = newValues[j]; + + for (var i = 0; i < _this._grid.rowFactory.rowCache.length; i++) { + var rowCache = _this._grid.rowFactory.rowCache[i]; + if (rowCache.entity == newValue) { + _this._grid.selectionService.setSelection(rowCache, true); + _this._grid.selectionService.lastClickedRow = rowCache; + break; + } + } + } + }); + }; + return KoGridRowSelectionPlugin; + })(); + koGridRowSelectionPlugin = KoGridRowSelectionPlugin; \ No newline at end of file diff --git a/plugins/koGridBootstrapTabPlugin.js b/plugins/koGridBootstrapTabPlugin.js new file mode 100644 index 00000000..af390dcc --- /dev/null +++ b/plugins/koGridBootstrapTabPlugin.js @@ -0,0 +1,19 @@ +// extension of the LayoutPlugin. Needed if the grid is displayed on a tab within bootstrap. +koGridBootstrapTabPlugin = function () { + var self = this; + this.grid = null; + $("a[data-toggle='tab']").on("shown.bs.tab", function () { + self.updateGridLayout(); + }); + + // The init method gets called during the koGrid binding handler execution. + self.onGridInit = function (grid) { + /* logic */ + self.grid = grid; + }; + this.updateGridLayout = function(){ + window.kg.domUtilityService.UpdateGridLayout(self.grid); + self.grid.configureColumnWidths(); + window.kg.domUtilityService.BuildStyles(self.grid); + }; +}