I have built a datagrid with pop up form editing based on the CRUD application demo
http://www.jeasyui.com/tutorial/app/crud.phpEverything works fine, except the delete record function.
It fires, the prompt comes up, no error message but I don't think it's getting the record ID for some reason.
Can anyone see anything incorrect in my code? Thanks
Javascript delete function:
function deleteRecord(){
var row = $('#dg').datagrid('getSelected');
if (row){
$.messager.confirm('Confirm','Are you sure you want to delete this record?',function(r){
if (r){
$.post('data_delete.php',{id:row.id},function(result){
if (result.success){
$('#dg').datagrid('reload'); // reload the user data
} else {
$.messager.show({ // show error message
title: 'Error',
msg: result.msg
});
}
},'json');
}
});
}
}
Datagrid html:
<table id="dg" title="Classes" class="easyui-datagrid"
url="data_select.php" idField="class_id" striped="true" loadMsg="Hey patience is a virtue"
toolbar="#toolbar" pagination="true" pageSize="30"
rownumbers="true" fitColumns="true" showFooter="true" singleSelect="true"
data-options="onDblClickRow:function(rowIndex, rowData){
editRecord();}">
<thead>
<tr>
<th id="idclass_id" field="class_id" width="35" align="right">ID</th>
<th id="idTimeCreated" field="TimeCreated" width="80">Created</th>
<th id="idTimeModified" field="TimeModified" width="80">Last Modified</th>
<th id="idClass" field="Class" >Class</th>
<th id="dgIsActive" field="IsActive" width="80">Active?</th>
<th id="idsortorder" field="sortorder" width="80">Sort Order</th>
</tr>
</thead>
</table>
<div id="toolbar">
<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="insertRecord()">New Line Item</a> |
<a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editRecord()">Edit Line Item</a> |
<a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="deleteRecord()">Remove Line Item</a>
</div>
data_delete.php file:
<?php
$id = intval($_REQUEST['class_id']);
include '../../common/conn.php';
$sql = "DELETE FROM class where class_id=$id";
$result = @mysql_query($sql);
if ($result){
echo json_encode(array('success'=>true));
} else {
echo json_encode(array('msg'=>'An error occurred while attempting to delete the record.'));
}
?>
Thanks for any insights...