Help with Delete from database

Help with Delete from database

btvbillbtvbill Posts: 11Questions: 0Answers: 0
edited December 2011 in General
I have searched through the forum and have come across solutions that indicate Ajax must be used to delete a datatable record from my database but I'm not sure where or how to implement such a function as I'm not a Javascript or Ajax expert. Basically, what would I need to do with the following code in order to access my ID database column and delete from the database? Thanks.
[code]

$(document).ready( function () {
var oTable = $('#example').dataTable().makeEditable({
sUpdateURL: "UpdateData.cfm",
sAddURL: "AddData.cfm",
sDeleteURL: "DeleteData.cfm"
});

} );

[/code]

Replies

  • allanallan Posts: 63,538Questions: 1Answers: 10,476 Site admin
    Assuming that the above code will send an Ajax request to the server to "DeleteData.cfm" when a delete is needed (I'm not 100% sure as the editable plug-in is 3rd party) then you just need to have your ColdFusion script do a DELETE FROM whatever_table WHERE id = _POST['id'] (you will be able to see for certain what is going on in the Ajax request with Firebug).

    Allan
  • btvbillbtvbill Posts: 11Questions: 0Answers: 0
    Thanks Allan. I do have the delete code in my ColdFusion page and it works. However, when I clcik the delete button there is a small window with a scroll bar opening that grays out my active window and appears (with nothing inside it). I've got Firebug going and it's not reporting any errors. Also, any ideas how I could get the page to refresh after the row is deleted? It doesn't show as deleted unless you manually refresh.
  • allanallan Posts: 63,538Questions: 1Answers: 10,476 Site admin
    The editable plug-in (at least my understanding of it) will delete the row on a successful delete. However you might need to return a certain code like 'ok' or 'done' or something like that. What are you currently returning?

    Allan
  • btvbillbtvbill Posts: 11Questions: 0Answers: 0
    It is spawning a small, scrollable page with no content and an "OK" button at the the bottom. When you click "OK" the window goes away but the deleted row does not show until you refresh the page.
  • btvbillbtvbill Posts: 11Questions: 0Answers: 0
    I' d like to try your code but I'm working in ColdFusion, not PHP and I have no idea what needs to go into the sAjaxSource and editable_ajax.php

    {code]
    $(document).ready(function() {
    var oTable = $('#example').dataTable( {
    "bJQueryUI": true,
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "server_processing.php",
    "sPaginationType": "full_numbers",
    "fnDrawCallback": function () {
    //alert( 'Number of rows: '+ this.fnGetNodes() );
    $('td', this.fnGetNodes()).editable( 'editable_ajax.php', {
    "callback": function( sValue, y ) {
    var aPos = oTable.fnGetPosition( this );
    oTable.fnUpdate( sValue, aPos[0], aPos[1] );
    },
    "submitdata": function ( value, settings ) {
    //alert( 'Got ID of: '+oTable.fnGetData( this.parentNode )[0] );
    return { "row_id": oTable.fnGetData( this.parentNode )[0],
    "column": oTable.fnGetPosition( this )[2]};
    },
    "height": "14px"
    } );
    }
    });
    });
    [/code]
  • allanallan Posts: 63,538Questions: 1Answers: 10,476 Site admin
    The format returned by sAjax source is described on this page: http://datatables.net/usage/server-side . That is language independent and there are language specific examples of how server-side processing can be done here: http://datatables.net/development/server-side/ .

    As for editable_ajax.php - that would simply to an UPDATE on the DB based on the data that is sent to it (which you can see using Firebug). My example doesn't do that, it just does an echo - again because I didn't want to write anything server-side specific.

    My editable demo is quite different from the editable plug-in from Jovan though. Which is it that you are trying to use? My demo doesn't include delete options for example - you would need to add them. There is also this blog post which you might find interesting: http://datatables.net/blog/Inline_editing

    Allan
This discussion has been closed.