View Full Version : Deleting a record on the grid using cellclick

2 May 2011, 3:06 AM
I would like to know how to delete a row/record from a grid on the click of a particular cells, which is marked with a delete icon image in it. I'm trying do so using 'cellclick' and since the grid doesn't have a selection model defined. The record has to be deleted in the database and also reflect in the grid.
The portion of the code used in the application is as follows,

var griduser = {
xtype: 'grid',
id: 'usertable',
store: storeuser,
trackMouseOver: false,
listeners: {
cellclick: function(o,row,col,e) {
if (col == 6) {
msg: 'Do you really want to delete this user?',
buttons: Ext.MessageBox.YESNO,
fn: function(btn){
if (btn == 'yes'){
var conn = new Ext.data.Connection();
url: 'user_delete.php',
params: {
action: 'delete',
id: e.record.id,
row: e.row
success: function(resp,opt) {
Ext.Msg.alert('Success', 'Selected user has been deleted');
failure: function(resp,opt) {
'Unable to delete movie');

columns: [
{header: "Login", dataIndex: 'login_id', width: 110},
{header: "Name", dataIndex: 'Name', width: 160},
{header: "Email Id", dataIndex: 'email', width: 210},
{header: "Group", dataIndex: 'group_name', width: 120},
{header: "Send Email", dataIndex: 'email', renderer: renderIcon, width: 70},
{header: "Edit", dataIndex: 'Edit', renderer: editIcon, width: 60},
{header: "Delete", dataIndex: 'Delete', renderer: deleteIcon, width: 60}
function deleteIcon(value, p, record) {
p.attr = 'ext:qtip="<b>Delete</b>"';
return (value, '<img src="images/icon_delete.png">') ;

2 May 2011, 3:32 AM

o.getStore().remove(e.record);instead of


Maybe you'll have to reload the grid's store too.

2 May 2011, 3:59 AM
Tried out with the changes mentioned, still the record clicked on does not get deleted. I've slightly modified the idea given for deleting a record with the delete button placed outside the grid and am not sure whether the values specified in the params: are correct. The php code being used is,

mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

mysql_query ("DELETE FROM users WHERE user_id = '".$_REQUEST['id']."'");

2 May 2011, 4:07 AM
There is no way for me to know if the params you send to your backend are correct. I'd try to get the record using the rowIndex. Check the GridPanel API (http://dev.sencha.com/deploy/ext-3.3.1/docs/?class=Ext.grid.GridPanel) for more help on the cellclick event.

After your backend successfully deleted the row, you'll want to reload your store.

Please update your posts and wrap your code with the proper tags. It helps me and others read your code.