Skip to content

Instantly share code, notes, and snippets.

@altintx
Created April 20, 2012 19:26
Show Gist options
  • Star 21 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save altintx/2431182 to your computer and use it in GitHub Desktop.
Save altintx/2431182 to your computer and use it in GitHub Desktop.
Swipe to Delete on Sencha Touch 2.0 list
/* Assuming:
* dataview is a { xtype: "list" }
* dataview.itemTpl includes a <div class="deleteplaceholder"></div>
*
* Delete button will disappear as soon as something is touched
*/
dataview.on("itemswipe", function(dataview, ix, target, record, event, options) {
if (event.direction == "left") {
var del = Ext.create("Ext.Button", {
ui: "decline",
text: "Delete",
style: "position:absolute;right:0.125in;",
handler: function() {
record.stores[0].remove(record);
record.stores[0].sync();
}
});
var removeDeleteButton = function() {
Ext.Anim.run(del, 'fade', {
after: function() {
del.destroy();
},
out: true
});
};
del.renderTo(Ext.DomQuery.selectNode(".deleteplaceholder", target.dom));
dataview.on({
single: true,
buffer: 250,
itemtouchstart: removeDeleteButton
});
dataview.element.on({
single: true,
buffer: 250,
touchstart: removeDeleteButton
});
}
}));
@trevoriancox
Copy link

Great, thanks. But for me there was an unwanted itemtap on the dataview item, fixed with:

handler: function(btn, e) {
e.stopEvent();
...
}

@arnolem
Copy link

arnolem commented Jan 14, 2013

For me, I must replace target.dom with target.element.dom

@toedter
Copy link

toedter commented Feb 21, 2013

Works great, thanks! I also had to replace target.dom with target.element.dom (Sencha Touch 2.1.1). If you want the delete button to fade in, just add

Ext.Anim.run(del, 'fade', {
      out : false
});

after del.renderTo(...

@kevinguto
Copy link

To anyone else who might have run into the same trouble as I did (Destry function not working): Please remember to add the requires: ['Ext.Anim'] since it is not loaded automatically with the default library.

@altintx
Copy link
Author

altintx commented Jul 25, 2013

Glad it's helping, folks!

@apachejboss
Copy link

hi,can you provide a simple example for this? and where should i put my swipe_to_delete.js file?

@comur
Copy link

comur commented Nov 26, 2014

Hi all,

If someone is interested to put buttons on swipe on a list item, i created a plugin for it:

https://github.com/Positive-LABS/SlideActionsPlugin

Hope it helps :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment