Skip to content

Loading…

adapted dean's ctrl-a select all code and updated Selection's test #94

Merged
merged 4 commits into from
Showing with 39 additions and 5 deletions.
  1. +17 −1 Selection.js
  2. +1 −1 Selector.js
  3. +5 −2 test/Selection.html
  4. +16 −1 test/Selector.html
View
18 Selection.js
@@ -19,6 +19,10 @@ return declare([List], {
// deselectOnRefresh: Boolean
// If true, the selection object will be cleared when refresh is called.
deselectOnRefresh: true,
+
+ //allowSelectAll: Boolean
+ // if true, allow ctrl/cmd-a to select all rows
+ allowSelectAll: false,
create: function(){
this.selection = {};
@@ -35,7 +39,7 @@ return declare([List], {
// object ids and values are true or false depending on whether an item is selected
selection: {},
// selectionMode: String
- // The selection mode to use, can be "multiple", "single", or "extended".
+ // The selection mode to use, can be "none", "multiple", "single", or "extended".
selectionMode: "extended",
setSelectionMode: function(mode){
@@ -143,6 +147,18 @@ return declare([List], {
// listen for actions that should cause selections
on(this.contentNode, on.selector(selector, this.selectionEvents), focus);
}
+
+ //if allowSelectAll boolean property is true, allow ctrl/cmd-a to select all rows
+ //also checks if selectionMode is not none before selecting all
+ if(this.allowSelectAll){
+ var selectAllHandle = on(this.contentNode, "keydown", function(event) {
+ if (event[ctrlEquiv] && event.keyCode == 65 && grid.selectionMode != "none") {
+ event.preventDefault();
+ grid.selectAll();
+ }
+ });
+ }
+
},
allowSelect: function(row){
View
2 Selector.js
@@ -116,7 +116,7 @@ define(["dojo/on", "dojo/aspect", "dojo/_base/sniff", "put-selector/put"], funct
var row = object && grid.row(object);
value = row && grid.selection[row.id];
- if(header && (type == "radio" || typeof object == "string")){
+ if(header && (type == "radio" || typeof object == "string" || !grid.allowSelectAll)){
cell.appendChild(document.createTextNode(object||""));
if(!grid._hasSelectorInputListener){
setupSelectionEvents();
View
7 test/Selection.html
@@ -48,7 +48,8 @@
gridRowNavigation = dojo.declare([Grid, Selection, Keyboard])({
store: testStore,
cellNavigation: false,
- columns: columns
+ columns: columns,
+ allowSelectAll: true
}, "grid-row-navigation");
var columns2 = {
@@ -59,7 +60,8 @@
};
gridCellNavigation = declare([Grid, CellSelection, Keyboard])({
store: testStore,
- columns: columns2
+ columns: columns2,
+ allowSelectAll: false
}, "grid-cell-navigation");
gridCellNavigationSingle = declare([Grid, CellSelection, Keyboard])({
store: testStore,
@@ -87,6 +89,7 @@
</head>
<body class="nihilo">
<h2>A grid with row-level selection (and row-level navigation)</h2>
+ <h3>Use ctrl/cmd-a to test keyboard select-all with different selectionModes</h3>
<div>Set selectionMode:
<button type="button" onclick="gridRowNavigation.setSelectionMode('none');">None</button>
<button type="button" onclick="gridRowNavigation.setSelectionMode('single');">Single</button>
View
17 test/Selector.html
@@ -32,6 +32,12 @@
col2: {label: 'Column 2', sortable: false},
col3: {label: 'Column 3'}
};
+ var columns2 = { // you can declare columns as an object hash (key translates to field)
+ col1: Selector({ type: "checkbox", label:"Select"}),
+ id: "ID",
+ col2: {label: 'Column 2', sortable: false},
+ col3: {label: 'Column 3'}
+ };
on(win.body(), "dgrid-select,dgrid-deselect",
function(event){
@@ -43,8 +49,15 @@
window.grid = dojo.declare([Grid, Selection, Keyboard])({
store: testStore,
selectionMode: "none",
- columns: columns
+ columns: columns,
+ allowSelectAll: true
}, "grid");
+ window.grid2 = dojo.declare([Grid, Selection, Keyboard])({
+ store: testStore,
+ selectionMode: "none",
+ columns: columns2,
+ allowSelectAll: false
+ }, "grid2");
var columnsRadio = { // you can declare columns as an object hash (key translates to field)
col1: Selector({ label: 'Radio', type: "radio", disabled: function(object){ return object.col3 == "read"; } }),
id: "ID",
@@ -73,6 +86,8 @@
Set selection mode to "extended"</button>
</div>
<div id="grid"></div>
+ <h2>A grid with select all disabled</h2>
+ <div id="grid2"></div>
<h2>A grid with radio selectors</h2>
<div>
<button type="button" onclick="gridRadio.setSelectionMode('none');">
Something went wrong with that request. Please try again.