New user, delete data from server question

New user, delete data from server question

XolinlevhXolinlevh Posts: 10Questions: 0Answers: 0
edited December 2012 in Editor
Hi all, so I am new to using DataTables and am currently working on a project which displays data from a MS SQL 08 server. Currently it displays it fine, sorts fine, but i need to add the ability to delete the data and i am confused as to where i would put the select/delete commands in the code. Ive searched around and havent been able to find anything that gives a rather clear example of how to do this (Though i could be blind and if someone has a link to an example of this that would be GREAT)

Thanks guys

Replies

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    I'm afraid I can't say on the server-side if you are using .NET. Editor will submit data in the format described here: http://editor.datatables.net/server/ . How the server acts on that, it up to yourself :-). Editor comes with a PHP implementation, and we will be looking to add a C# implementation early next year.

    Regards,
    Allan
  • XolinlevhXolinlevh Posts: 10Questions: 0Answers: 0
    Thanks! Ill read over that and see what i can come up with!
  • XolinlevhXolinlevh Posts: 10Questions: 0Answers: 0
    edited December 2012
    Hmm guess im still a bit confused. Im looking around and cant really find where the action triggered by clicking the 'delete' button is. I used the Generator to make a simple table, so everything is rather standard. the button is created by [code] { "sExtends": "editor_remove", "editor": editor } [/code] and so basically i am just trying to find what that executes in the editor, so i can set it up with our SQL DELETE command. My goal is for the user to be able to select multiple rows if needed, then click delete, and have it then execute a SQL statement over on our server to remove the rows from the database.

    PS im sorry if these questions are somewhat noob....but im quite new to this :)
  • XolinlevhXolinlevh Posts: 10Questions: 0Answers: 0
    Updating my thought process so far. If im following the tutorials and examples right, i added the [code] $(document).ready(function() {
    var editor = new $.fn.dataTable.Editor( {
    "sDeleteURL": "php/DeleteData.php",[/code] line, and DeleteData.php is: [code]
    <?php
    $myServer = "**************";
    $myUser = "*********";
    $myPass = "*************";
    $myDB = "**************";

    //connection to the database
    $dbhandle = mssql_connect($myServer, $myUser, $myPass)
    or die("Couldn't connect to SQL Server on $myServer");

    //select a database to work with
    $selected = mssql_select_db($myDB, $dbhandle)
    or die("Couldn't open database $myDB");

    //declare the SQL statement that will query the database
    $query = "DELETE Id ";
    $query .= "FROM MDR ";
    $query .= "WHERE name='3'";

    //execute the SQL query and return records
    $result = mssql_query($query);

    $numRows = mssql_num_rows($result);
    echo "" . $numRows . " Row" . ($numRows == 1 ? "" : "s") . " Returned ";

    //display the results
    while($row = mssql_fetch_array($result))
    {
    echo "" . $row["id"] . $row["name"] . $row["year"] . "";
    }
    //close the connection
    mssql_close($dbhandle);
    ?>
    [/code]

    which (once i finish tying it to the delete button) connect to my MSSQL DB, delete from the MDR database whatever value i pass in. But i still cant seem to get this triggered.
  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    [code]
    { "sExtends": "editor_remove", "editor": editor }
    [/code]

    Editor creates a TableTools button ( http://datatables.net/extras/tabletools/ ) which handles the click event.

    > "sDeleteURL": "php/DeleteData.php"

    Editor doesn't have an `sDeleteURL` parameter. Editor uses the `ajaxUrl` option: http://editor.datatables.net/options/#ajaxUrl .

    Allan
  • XolinlevhXolinlevh Posts: 10Questions: 0Answers: 0
    edited December 2012
    Hmm so ive made a few changes based on that, still no luck. Code is now as follows:

    table.DataModel.js:
    [code]

    (function($){

    $(document).ready(function() {
    var editor = new $.fn.dataTable.Editor( {
    "aaSorting": [[2, "desc"]],
    "bProcessing": true,
    "bServerSide": true,
    "bStateSave": true,
    "ajaxUrl": {
    "editor_remove": "GET /php/DeleteData.php",
    },
    "domTable": "#DataModel",
    "fields": [
    {
    "label": "ID",
    "name": "id",
    "type": "text"
    },
    {
    "label": "Version",
    "name": "version",
    "type": "text"
    },

    ]
    } );

    $('#DataModel').dataTable( {
    "sDom": "Tfrtip",
    "bProcessing": true,
    "sPaginationType": "full_numbers",
    "aoColumns": [
    {
    "mData": "id"
    },
    {
    "mData": "version"
    },
    ],
    "oTableTools": {
    "sRowSelect": "multi",
    "aButtons": [

    { "sExtends": "editor_create", "editor": editor },
    { "sExtends": "editor_remove", "editor": editor }
    ]
    }
    } );
    } );

    }(jQuery));
    [/code]

    the DeleteData.php is the same as above. I have created a few entires in the database (one with Id=3 so if the DeleteData is called correctly it should remove it....but its not) It sits there doing a little thinking icon on the confirm delete pop-up, but the entry persists in my database
  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    [code]
    "ajaxUrl": {
    "editor_remove": "GET /php/DeleteData.php",
    },
    [/code]

    There is no `editor_remove` option either. From the documentation:

    > When given as an object, the create, edit and remove properties should be defined

    It also doesn't have `aaSorting` , `bProcessing` etc options - they are DataTables options. Editor options are defined on the documentation page I linked to before.

    Allan
  • XolinlevhXolinlevh Posts: 10Questions: 0Answers: 0
    Ah k, i was mixing my examples up, combined Tables and Editor. We are re-adjusting how we pass our data back, instead we now want to just have the ajax return the value of a row we check. Created a checkbox next to each row, when checked, and the user presses a delete button, it will pass back the row # to the server which will delete the row from its side. Sorry im so totally new to all this, taking a bit longer for it to click with me
This discussion has been closed.