DataTable Delete Based on Select
DataTable Delete Based on Select
All,
I am new to using data tables and I have gotten my add and update to work, but having trouble on how to have this delete a row based on a radio button selection and delete from DB and DataTable.
The issue I am having is exactly how to get the delete function working, but please feel free to comment if I could be doing the add and update in a better way. Definitely not certain I have done this is the standard way.
I appreciate any help that you can provide as I have been fighting with this and I am sure it is simple but am missing the pieces to pull it together.
My Code is below and will add comments as
[code]
<?php
session_start();
require_once 'util/RoleBitMaskHelper.class.php';
if(!isset($_SESSION['username']) || !RoleBitMaskHelper::isAuthorized($_SESSION['rolebm'],RoleBitMaskHelper::ADMIN_ROLE)) {
header("location:accessdenied.php");
}
$username = $_SESSION['username'];
?>
var oTable;
oTable = $(document).ready(function() {
$('#messages').dataTable( {
"sScrollX": "100%",
"sScrollXInner": "110%",
"bScrollCollapse": true,
"sPaginationType": "full_numbers"
} );
/* Add a click handler for the delete row */
/* Need this event handler to delete row from the DataTable and delete row from mysql database by calling php function to delete this table */
$('#delete').click( function() {
var anSelected = fnGetSelected( oTable );
oTable.fnDeleteRow( anSelected[0] );
} );
} );
/* Get the rows which are currently selected */
function fnGetSelected( oTableLocal )
{
var aReturn = new Array();
var aTrs = oTableLocal.fnGetNodes();
for ( var i=0 ; i 0 && foundselected==false) {
alert('Please select an item to work on');
return;
}
document.location.href=str;
}
@import "DataTable/css/esc_table.css";
<?php
// MySQL host name, user name, password, database, and table
require_once 'db_params.php';
?>
Update Messages
To edit a message click on the source link.
Select the check box next to a message and click delete to delete it.
Columns can be sorted in ascending or descending order by clicking on the column name.
Select
Source
Message
Message Date
Date Added
Date Modified
User
Select
Source
Message
Message Date
Date Added
Date Modified
User
<?php require_once 'retrieveusers.php';?>
/* Actual generated data from this looks like the below content */
/* I want to select the radio button and then press the delete button and have both the mysql and datatable updated */
announcementsChurch is cancelled due to weather
2011-11-162011-11-16 19:38:23
2011-11-16 19:38:23
whefner
testtest2
0000-00-00
0000-00-00 00:00:00
0000-00-00 00:00:00
whefner
[/code]
I am new to using data tables and I have gotten my add and update to work, but having trouble on how to have this delete a row based on a radio button selection and delete from DB and DataTable.
The issue I am having is exactly how to get the delete function working, but please feel free to comment if I could be doing the add and update in a better way. Definitely not certain I have done this is the standard way.
I appreciate any help that you can provide as I have been fighting with this and I am sure it is simple but am missing the pieces to pull it together.
My Code is below and will add comments as
[code]
<?php
session_start();
require_once 'util/RoleBitMaskHelper.class.php';
if(!isset($_SESSION['username']) || !RoleBitMaskHelper::isAuthorized($_SESSION['rolebm'],RoleBitMaskHelper::ADMIN_ROLE)) {
header("location:accessdenied.php");
}
$username = $_SESSION['username'];
?>
var oTable;
oTable = $(document).ready(function() {
$('#messages').dataTable( {
"sScrollX": "100%",
"sScrollXInner": "110%",
"bScrollCollapse": true,
"sPaginationType": "full_numbers"
} );
/* Add a click handler for the delete row */
/* Need this event handler to delete row from the DataTable and delete row from mysql database by calling php function to delete this table */
$('#delete').click( function() {
var anSelected = fnGetSelected( oTable );
oTable.fnDeleteRow( anSelected[0] );
} );
} );
/* Get the rows which are currently selected */
function fnGetSelected( oTableLocal )
{
var aReturn = new Array();
var aTrs = oTableLocal.fnGetNodes();
for ( var i=0 ; i 0 && foundselected==false) {
alert('Please select an item to work on');
return;
}
document.location.href=str;
}
@import "DataTable/css/esc_table.css";
<?php
// MySQL host name, user name, password, database, and table
require_once 'db_params.php';
?>
Update Messages
To edit a message click on the source link.
Select the check box next to a message and click delete to delete it.
Columns can be sorted in ascending or descending order by clicking on the column name.
Select
Source
Message
Message Date
Date Added
Date Modified
User
Select
Source
Message
Message Date
Date Added
Date Modified
User
<?php require_once 'retrieveusers.php';?>
/* Actual generated data from this looks like the below content */
/* I want to select the radio button and then press the delete button and have both the mysql and datatable updated */
announcementsChurch is cancelled due to weather
2011-11-162011-11-16 19:38:23
2011-11-16 19:38:23
whefner
testtest2
0000-00-00
0000-00-00 00:00:00
0000-00-00 00:00:00
whefner
[/code]
This discussion has been closed.
Replies
Allan
Can you please direct, me on how to get the value of a specific table cell.
var oTT = TableTools.fnGetInstance( 'messages' );
var aSelectedTrs = oTT.fnGetSelected();
$(aSelectedTrs).has('td:eq(1):contains("announcements")'); //selected rows that have "announcements" in the Source cell
[/code]
$('#Update').click( function() {
var anSelected = fnGetSelected( oTable );
var source = $('anSelected[0]');
var b=source;
//alert(source);
} );
$('#Update').click( function() {
var anSelected = fnGetSelected( oTable );
var tds = $(anSelected).eq(0).find('td');
var source = tds.eq(0).text();
alert(source);
} );