Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CellSelection and Row selection working together #419

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 54 additions & 2 deletions CellSelection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, wholeRow){
if(wholeRow){
this.selectFullRow(cell, toCell, value);
}
var i, id;
if(value === undefined){
// default to true
Expand Down
3 changes: 3 additions & 0 deletions Selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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".
Expand Down
4 changes: 2 additions & 2 deletions selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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.
Expand Down