New user, delete data from server question
New user, delete data from server question
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
Thanks guys
This discussion has been closed.
Replies
Regards,
Allan
PS im sorry if these questions are somewhat noob....but im quite new to this :)
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.
{ "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
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
"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