Is there a method can select all selected rows
hhzhaoheng opened this issue · 2 comments
hhzhaoheng commented
<title>Grids and Stores</title>
<style>
.heading {
font-weight: bold;
padding-bottom: 0.25em;
}
.dgrid {
width: 70%;
margin: 10px;
}
.field-col1 {
width: 40px;
}
#grid-complex .dgrid-cell {
height: 2em; /* force consistent heights across columnset cells */
}
.dgrid-column-set-0 {
width: 42px;
}
#grid .selector{
width:2em;
}
</style>
<script src="../js/dojo/dojo/dojo.js"></script>
<script>
require([
'dojo/_base/declare',
'dojo/dom',
'dojo/on',
'dojo/_base/array',
'dojo/json',
'dstore/RequestMemory',
'dstore/Trackable',
'dgrid/Grid',
'dgrid/Keyboard',
'dgrid/extensions/Pagination',
'dgrid/Selection',
'dgrid/Selector',
'dojo/domReady!'
], function (declare, dom, on, arrayUtil, json, RequestMemory, Trackable, Grid, Keyboard, Pagination, Selection, Selector) {
on(document.body, "dgrid-select,dgrid-deselect",
function(event){
var msg = (event.type == "dgrid-deselect" ? "de" : "") + "selected";
console.log(event.grid.id + ": " + msg +
(event.parentType ? " (via " + event.parentType + "): " : ": "),
arrayUtil.map(event.rows, function(row){ return row.id; }).join(", "));
console.log("selection: ", json.stringify(event.grid.selection, null, " "));
}
);
var MyStore = declare('MyStore', [ RequestMemory, Trackable]);
var grid = new (declare([ Grid, Pagination, Selection, Selector, Keyboard]))({
collection: new MyStore({ target: 'hof-batting.json' }),
selectionMode: "none",
allowSelectAll: true,//false则不显示全选复选框,true则显示,label的值会被覆盖
allowTextSelection:true,
allowSelect: function(row){
return row.data.first !== 'Cap';
},
className: 'dgrid-autoheight',
columns: [
{selector: 'checkbox', className: "selector", label:''},
{label:'First Name',field:'first'},
{label:'Last Name',field:'last'},
{label:'Games Played',field:'totalG'}
]
}, 'grid');
grid.startup();
grid.on('.selector:checked', function (event) {
var row = grid.row(event);
console.log('Row clicked:', row.data);
});
on(dom.byId('selAll'), 'click', function () {
grid.selectAll();
});
on(dom.byId('deselAll'), 'click', function () {
grid.clearSelection();
});
//Is there a method can select all selected rows
**# on(dom.byId('getSels'),'click',function (evt) {
var rows = grid.selection;
var i = 0;
grid.collection.forEach(function (item) {
var i = 1;
})**
});
});
</script>
Demo: 选择框
全部选择 全部取消 获取选中的数据(select all by self)edhager commented
Give this a try:
on(dom.byId('getSels'),'click',function (evt) {
var selection = grid.selection;
Object.keys(selection).forEach(function (id) {
// If a row was selected and then deselected individually, the id will be a key
// in grid.selection but the value will be "false".
if (selection [id]) {
var row = grid.row(id);
console.group('Player id:', id);
console.log('row object:', row);
console.log('row DOM node:', row.element);
console.log('data object:', row.data);
console.groupEnd();
}
});
});
msssk commented
It looks like this has been answered.
This is the bug tracker. Please use Stack Overflow for usage and support requests.