jQuery UI Widgets › Forums › Grid › Delete button not firing
This topic contains 3 replies, has 2 voices, and was last updated by mr_putersmit 12 years, 1 month ago.
-
AuthorDelete button not firing Posts
-
Hello
I am having a terrible time trying to get the delete function to work. I studied the CRUD example and thought I had it, but the code I have doesn’t fire at all. Also, when I click the button there is nothing coming back in firebug, errors of code. I would be grateful if someone could check my code and point out my errors. Thanksindex.php
$(document).ready(function () {
// prepare the data
var source =
{
datatype: "json",
datafields: [
{ name: 'id', type: 'number' },
{ name: 'slot'},
{ name: 'service'},
{ name: 'activity'},
{ name: 'department'},
{ name: 'company'},
{ name: 'user'},
{ name: 'item'},
{ name: 'filebox'},
{ name: 'destroyedby'},
{ name: 'destroyedbydate', type: 'date', format: 'yyyy-MM-dd HH:mm:ss'},
{ name: 'destdate', type: 'date', format: 'yyyy-MM-dd HH:mm:ss'},
{ name: 'date', type: 'date', format: 'yyyy-MM-dd HH:mm:ss'},
{ name: 'type'},
{ name: 'notes'},
{ name: 'new'},
],
id: 'id',
url: 'data.php',
deleterow: function (rowid) {
// synchronize with the server - send delete command
var data = "delete=true&id=" + rowid;
$.ajax({
dataType: 'json',
url: 'data.php',
data: data,
success: function (data, status, xhr) {
// delete command is executed.
alert('success');}
});
}
};var dataAdapter = new $.jqx.dataAdapter(source);
$("#deleterowbutton").jqxButton({ theme: 'classic' });
$("#jqxgrid").jqxGrid(
{
source: source,
theme: 'classic',
pageable: true,
sortable: true,
filterable: true,
autoheight: true,
altrows: true,
pagesizeoptions: ['10', '20', '30', '40'],
width: 800,
rowdetails: true,
columns: [
{ text: 'id', datafield: 'id', width: 40},
{ text: 'Service', datafield: 'service', width: 100},
{ text: 'Activity', datafield: 'activity', width: 100 },
{ text: 'Department', datafield: 'department', width: 90 },
{ text: 'Company', datafield: 'company', width: 90 },
{ text: 'User', datafield: 'user', width: 150},
{ text: 'Item', datafield: 'item', width: 100 },
{ text: 'Filebox', datafield: 'filebox', width: 180 },
{ text: 'Destroyed By', datafield: 'destroyedby', width: 120 },
{ text: 'Destroyed By Date', datafield: 'destroyedby_date', columntype: 'date', width: 180, cellsformat: "dd/MM/yyyy hh:mm:ss"},
{ text: 'Destroyed Date', datafield: 'destdate', columntype: 'date', width: 180, cellsformat: "dd/MM/yyyy hh:mm:ss" },
{ text: 'Date', datafield: 'date', columntype: 'date', width: 180, cellsformat: "dd/MM/yyyy hh:mm:ss" },
{ text: 'Quantity', datafield: 'quantity', width: 70 },
{ text: 'Type', datafield: 'type', width: 70 },]
});
}); // delete row.
$("#deleterowbutton").bind('click', function () {
var selectedrowindex = $("#jqxgrid").jqxGrid('getselectedrowindex');
var rowscount = $("#jqxgrid").jqxGrid('getdatainformation').rowscount;
if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
var id = $("#jqxgrid").jqxGrid('getrowid', selectedrowindex);
$("#jqxgrid").jqxGrid('deleterow', id);alert("click");
}
});data.php
$row['id'],
'slot' => $row['slot'],
'service' => $row['service'],
'activity' => $row['activity'],
'department' => $row['department'],
'company' => $row['company'],
'user' => $row['user'],
'item' => $row['item'],
'filebox' => $row['filebox'],
'destroyedby' => $row['destroyedby'],
'destroyedbydate' => $row['destroyedby_date'],
'destdate' => $row['destroydate'],
'date' => $row['date'],
'quantity' => $row['quantity'],
'type' => $row['type'],
'notes' => $row['notes'],
'new' => $row['new']);
}echo json_encode($act);
?>Can anyone point me in the right direction to solve this problem? Many thanks
Hi mr_putersmit,
I think that this code:
$("#deleterowbutton").bind('click', function () {var selectedrowindex = $("#jqxgrid").jqxGrid('getselectedrowindex');var rowscount = $("#jqxgrid").jqxGrid('getdatainformation').rowscount;if (selectedrowindex >= 0 && selectedrowindex < rowscount) {var id = $("#jqxgrid").jqxGrid('getrowid', selectedrowindex);$("#jqxgrid").jqxGrid('deleterow', id);alert("click");}});
is outside of your script because you have
});});
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comThank you Peter
-
AuthorPosts
You must be logged in to reply to this topic.