EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: andrux on May 09, 2013, 02:47:18 PM



Title: destroyUrl not firing
Post by: andrux on May 09, 2013, 02:47:18 PM
Hello again.

I'm trying to get my datagrid to update and delete records from the database, but I run into the problem that the destroyUrl property is not working. I haven't put all logic inside my destroy.php file to actually delete a record, I wanted to try something simple before that, just update a record in the database with 'test delete succeeded', so that I rule out everything else.

The updateUrl correctly updates the database with 'test update succeeded', but the destroyUrl is not doing anything.

I have my datagrid initialized like this:

Code:
	jQuery( document ).ready( function ( $ ) {
$( '#dg' ).edatagrid({
url: 'get.php',
updateUrl: 'update.php',
destroyUrl: 'destroy.php',
title: 'my datagrid',
width: 'auto',
height: '400',
pagination: true,
singleSelect: true,
idField: 'option_id',
fitColumns: true,
rownumbers: true,
sortName: 'option_id',
sortOrder: 'asc',
pageSize: 10,
pageList: [ 10, 20, 30 ],
columns: columnsArray,
onBeforeEdit: function( index, row ) {
row.editing = true;
updateActions( index );
},
onAfterEdit: function( index, row ) {
row.editing = false;
updateActions( index );
},
onCancelEdit: function( index, row ) {
row.editing = false;
updateActions( index );
}
});
});

function updateActions( index ) {
jQuery( '#dg' ).datagrid( 'updateRow', {
index: index,
row: {}
});
}

function getRowIndex( target ) {
var tr = jQuery( target ).closest( 'tr.datagrid-row' );
return parseInt( tr.attr( 'datagrid-row-index' ) );
}

function editrow( target ) {
jQuery( '#dg' ).datagrid( 'beginEdit', getRowIndex( target ) );
}

function deleterow( target ) {
jQuery.messager.confirm( 'Confirm', 'Are you sure you want to delete this record?', function( r ) {
if ( r ){
jQuery( '#dg' ).datagrid( 'deleteRow', getRowIndex( target ) );
}
});
}

function saverow( target ) {
jQuery( '#dg' ).datagrid( 'endEdit', getRowIndex( target ) )
}

function cancelrow( target ) {
jQuery( '#dg' ).datagrid( 'cancelEdit', getRowIndex( target ) );
}


Am I missing something here?

Thank you in advance for your help.


Title: Re: destroyUrl not firing
Post by: joe on May 09, 2013, 10:31:06 PM
    $( '#dg' ).edatagrid( 'destroyRow');


Title: Re: destroyUrl not firing
Post by: andrux on May 10, 2013, 10:18:40 AM
Thanks, Joe, but it didn't work.

What I ended up doing is modifying the deleterow function like this:

Code:
	function deleterow( target ) {
$.messager.confirm( 'Confirm', 'Are you sure you want to delete this record?', function( r ) {
if ( r ) {
var data = {};
data.rows = $( '#dg' ).datagrid( 'getRows' )[ getRowIndex( target ) ];

$.post( 'destroy.php', data, function( response ) {
if ( response == 'success' )
$( '#dg' ).datagrid( 'deleteRow', getRowIndex( target ) );
});
}
});
}

Thank you all


Title: Re: destroyUrl not firing
Post by: joe on May 10, 2013, 10:29:02 AM
your original code uses "edatagrid" and not "datagrid".  Note the difference.


Title: Re: destroyUrl not firing
Post by: andrux on May 10, 2013, 10:31:27 AM
Yes, I see the difference, but it's working like this so I'll just leave it like that.

Thank you