Skip to content

Commit

Permalink
added a bulk processing option to improve speed and added some events
Browse files Browse the repository at this point in the history
  • Loading branch information
VinylFox committed Dec 31, 2010
1 parent 66eae9a commit 9ae1a1f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 9 deletions.
6 changes: 3 additions & 3 deletions examples/grid/array-grid-datadrop.html
Expand Up @@ -14,9 +14,9 @@

<script type="text/javascript" src="../../adapter/ext/ext-base.js"></script>

<script type="text/javascript" src="../../ext-all.js"></script>
<script type="text/javascript" src="../ux/Override.js"></script>
<script type="text/javascript" src="../ux/Ext.ux.DataDrop.js"></script>
<script type="text/javascript" src="../../ext-all-debug.js"></script>
<script type="text/javascript" src="../../src/Override.js"></script>
<script type="text/javascript" src="../../src/Ext.ux.DataDrop.js"></script>
<script type="text/javascript" src="array-grid-datadrop.js"></script>

</head>
Expand Down
7 changes: 6 additions & 1 deletion examples/grid/array-grid-datadrop.js
Expand Up @@ -88,7 +88,12 @@ Ext.onReady(function(){
autoExpandColumn: 'company',
height: 350,
width: 600,
title: 'Array Grid'
title: 'Array Grid',
listeners: {
'beforedatadrop': function(){console.log(arguments);/* can do "return false;" here to cancel processing the drop*/},
'datadrop': function(){console.log(arguments)},
'afterdatadrop': function(){console.log(arguments)}
}
});

// render the grid to the specified div in the page
Expand Down
45 changes: 40 additions & 5 deletions src/Ext.ux.DataDrop.js
Expand Up @@ -76,11 +76,13 @@ Ext.ux.grid.DataDrop = (function(){
var nv = el.value;
el.blur();
if (nv !== '') {
if (this.fireEvent('beforedatadrop',this,nv,el)){
var store = this.getStore(), Record = store.recordType;
el.value = '';
var rows = nv.split(lineEndRE), cols = this.getColumnModel().getColumnsBy(function(c){
return !c.hidden;
}), fields = Record.prototype.fields;
}), fields = Record.prototype.fields, recs = [];
this.fireEvent('datadrop',this,rows);
if (cols.length && rows.length) {
for (var i = 0; i < rows.length; i++) {
var vals = rows[i].split(sepRe), data = {};
Expand All @@ -91,19 +93,43 @@ Ext.ux.grid.DataDrop = (function(){
data[fldName] = fld ? fld.convert(vals[k]) : vals[k];
}
var newRec = new Record(data);
store.add(newRec);
var idx = store.indexOf(newRec);
this.view.focusRow(idx);
Ext.get(this.view.getRow(idx)).highlight();
recs.push(newRec);
if (!Ext.ux.grid.DataDrop.addBulk){
store.add(newRec);
if (Ext.ux.grid.DataDrop.highlightNewRows){
var idx = store.indexOf(newRec);
this.view.focusRow(idx);
Ext.get(this.view.getRow(idx)).highlight();
}
}
}
}
if (Ext.ux.grid.DataDrop.addBulk && recs && recs.length){
store.add(recs);
if (Ext.ux.grid.DataDrop.highlightNewRows){
for (var i = 0; i < recs.length; i++){
var idx = store.indexOf(recs[i]);
this.view.focusRow(idx);
Ext.get(this.view.getRow(idx)).highlight();
}
}
}
this.fireEvent('afterdatadrop',this,recs);
resizeDropArea.call(this);
}
}else{
el.value = '';
}
}
}

return {
init: function(cmp){
cmp.addEvents({
'beforedatadrop': true,
'datadrop': true,
'afterdatadrop': true
});
Ext.apply(cmp, {
changeValueTask: {
run: function(){
Expand All @@ -118,3 +144,12 @@ Ext.ux.grid.DataDrop = (function(){
}
};
})();

/**
* @cfg addBulk {boolean} set true to add all records at once, isntead of individually.
*/
Ext.ux.grid.DataDrop.addBulk = true;
/**
* @cfg highlightNewRows {boolean} set true to highlight rows upon insertion.
*/
Ext.ux.grid.DataDrop.highlightNewRows = true;

0 comments on commit 9ae1a1f

Please sign in to comment.