From 8adc5861ea745e782fd29462751fcb604d8c59fc Mon Sep 17 00:00:00 2001 From: terebikun Date: Thu, 7 Feb 2013 11:49:38 -0600 Subject: [PATCH 1/4] Update CellSelection.js Create a new method called SelectFullRow which is a copy of Select on Selection.js this one receives an extra parameter that marks if the event is a click on the selector checkbox or radio button so the grid can select the whole row --- CellSelection.js | 56 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/CellSelection.js b/CellSelection.js index ca0ae4b5b..938500c63 100644 --- a/CellSelection.js +++ b/CellSelection.js @@ -6,8 +6,60 @@ return declare(Selection, { // ensure we don't select when an individual cell is not identifiable selectionDelegate: ".dgrid-cell", - - select: function(cell, toCell, value){ + selectFullRow: function(row, toRow, value){ + if(value === undefined){ + // default to true + value = true; + } + if(!row.element){ + row = this.row(row); + } + if(this.allowSelect(row)){ + var selectionRow = this.selectionRow; + var previousValue = selectionRow[row.id]; + if(value === null){ + // indicates a toggle + value = !previousValue; + } + var element = row.element; + if(!value && !this.allSelected){ + delete this.selectionRow[row.id]; + }else{ + selectionRow[row.id] = value; + } + if(element){ + // add or remove classes as appropriate + if(value){ + put(element, ".dgrid-selected.ui-state-active"); + }else{ + put(element, "!dgrid-selected!ui-state-active"); + } + } + if(value != previousValue && element){ + // add to the queue of row events + this._selectionEventQueue(value, "rows").push(row); + } + + if(toRow){ + if(!toRow.element){ + toRow = this.row(toRow); + } + var toElement = toRow.element; + var fromElement = row.element; + // find if it is earlier or later in the DOM + var traverser = (toElement && (toElement.compareDocumentPosition ? + toElement.compareDocumentPosition(fromElement) == 2 : + toElement.sourceIndex > fromElement.sourceIndex)) ? "down" : "up"; + while(row.element != toElement && (row = this[traverser](row))){ + this.select(row); + } + } + } + }, + select: function(cell, toCell, value, selectFullRow){ + if(selectFullRow){ + selectFullRow(row, toRow, value); + } var i, id; if(value === undefined){ // default to true From 0956312f6a6656353a91a3a7270887d2203ad124 Mon Sep 17 00:00:00 2001 From: terebikun Date: Thu, 7 Feb 2013 11:52:57 -0600 Subject: [PATCH 2/4] Update Selection.js in the case when using CellSelection this object will hold the rows selected when a selector plug in is in use. in this fashion we can tell between the rows and cells selected. --- Selection.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Selection.js b/Selection.js index 7c5de24e3..5e10a7ed1 100644 --- a/Selection.js +++ b/Selection.js @@ -116,6 +116,9 @@ return declare(null, { // An object where the property names correspond to // object ids and values are true or false depending on whether an item is selected selection: {}, + // selectionRow: + // Stores an selection object exclusively for the selector when a full row is selected. + selectionRow: {}, // selectionMode: String // The selection mode to use, can be "none", "multiple", "single", or "extended". From 5897279d461fed6b913e37cae6adbca89466c272 Mon Sep 17 00:00:00 2001 From: terebikun Date: Thu, 7 Feb 2013 11:55:49 -0600 Subject: [PATCH 3/4] Update selector.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit an extra parameter for the grid.select call so it marks it's a selector the oneĀ  triggering the event --- selector.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/selector.js b/selector.js index 29e14b5c5..e0ae210d1 100644 --- a/selector.js +++ b/selector.js @@ -69,7 +69,7 @@ function(kernel, arrayUtil, on, aspect, has, put){ if(type == "radio"){ if(!lastRow || lastRow.id != row.id){ grid.clearSelection(); - grid.select(row, null, true); + grid.select(row, null, true, true); grid._lastSelected = row.element; } }else{ @@ -82,7 +82,7 @@ function(kernel, arrayUtil, on, aspect, has, put){ lastRow = null; } lastRow = event.shiftKey ? lastRow : null; - grid.select(lastRow || row, row, lastRow ? undefined : null); + grid.select(lastRow || row, row, lastRow ? undefined : null, true); grid._lastSelected = row.element; }else{ // No row resolved; must be the select-all checkbox. From 8367147f03c1ca48d75a2662dfd9f29e1f708657 Mon Sep 17 00:00:00 2001 From: terebikun Date: Thu, 7 Feb 2013 14:55:29 -0600 Subject: [PATCH 4/4] Update CellSelection.js fixed some typos I made --- CellSelection.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CellSelection.js b/CellSelection.js index 938500c63..7b40788d8 100644 --- a/CellSelection.js +++ b/CellSelection.js @@ -56,9 +56,9 @@ return declare(Selection, { } } }, - select: function(cell, toCell, value, selectFullRow){ - if(selectFullRow){ - selectFullRow(row, toRow, value); + select: function(cell, toCell, value, wholeRow){ + if(wholeRow){ + this.selectFullRow(cell, toCell, value); } var i, id; if(value === undefined){