我在mysql中使用了editablegrid。它将数据绑定并显示到我的网格上。但是,当我尝试编辑或更新网格时,它无法做到这一点。
下面是我的loaddata的一些代码。
$grid->addColumn('CertificateNo', 'CertificateNo', 'integer', NULL, false);
$grid->addColumn('ID', 'ID', 'integer');
$grid->addColumn('QuizNo', 'Test No', 'integer');
$grid->addColumn('Received', 'Received', 'boolean');
$grid->addColumn('DateReceived', 'Date Received', 'datetime'); 以下是更新脚本的代码:
// Get all parameters provided by the javascript
$colname = $mysqli->real_escape_string(strip_tags($_POST['colname']));
$id = $mysqli->real_escape_string(strip_tags($_POST['id']));
$coltype = $mysqli->real_escape_string(strip_tags($_POST['coltype']));
$value = $mysqli->real_escape_string(strip_tags($_POST['newvalue']));
$tablename = $mysqli->real_escape_string(strip_tags($_POST['tablename']));
/ This very generic. So this script can be used to update several tables.
$return=false;
if ( $stmt = $mysqli->prepare("UPDATE ".$tablename." SET ".$colname." = ? WHERE id = ?")) {
$stmt->bind_param("si",$value, $id);
$return = $stmt->execute();
$stmt->close();下面是javascript的一部分,它将值传递给我的update.php脚本。
function updateCellValue(editableGrid, rowIndex, columnIndex, oldValue, newValue, row, onResponse)
{
$.ajax({
url: 'update.php',
type: 'POST',
dataType: "html",
data: {
tablename : editableGrid.name,
id: editableGrid.getRowId(rowIndex),
newvalue: editableGrid.getColumnType(columnIndex) == "boolean" ? (newValue ? 1 : 0) : newValue,
colname: editableGrid.getColumnName(columnIndex),
coltype: editableGrid.getColumnType(columnIndex)
},
success: function (response)
{
// reset old value if failed then highlight row
var success = onResponse ? onResponse(response) : (response == "ok" || !isNaN(parseInt(response))); // by default, a sucessfull reponse can be "ok" or a database id
if (!success) editableGrid.setValueAt(rowIndex, columnIndex, oldValue);
highlight(row.id, success ? "ok" : "error");
},
error: function(XMLHttpRequest, textStatus, exception) { alert("Ajax failure\n" + errortext); },
async: true
});这个模板附带了一个javascript editablegrid-2.0.1。我注意到这个问题与主键有关。在可以从www.editablegrid.net找到的演示中,表有主键ID,而我的表有CertificateNo,但是我的表中的ID不是主键。
所以我改变了
$grid->addColumn('ID', 'ID', 'integer', NULL, false);至
$grid->addColumn('CertificateNo', 'CertificateNo', 'integer', NULL, false); 现在我不能更新网格。
发布于 2014-11-08 20:42:17
我也有同样的问题,你可以在loaddata.php中看到下面的代码
$grid->addColumn('action', 'Action', 'html', NULL, false, 'id'); 将最后一列中的'id‘替换为'CertificateNo’,如下所示
$grid->addColumn('action', 'Action', 'html', NULL, false, 'CertificateNo');然后重新加载页面以查看更改。
发布于 2013-10-09 08:27:54
update.php使用$_POST' id‘,也许您应该将其改为$_POST’‘CertificateNo’,并将id作为另一列处理,因为它不再是主键。
发布于 2014-03-17 22:28:34
我也有同样的问题。您必须在js/demo.js中进行更改
function DatabaseGrid()
{
this.editableGrid = new EditableGrid("HERE!!! Chage to name of your sql table", {...并且还将你的CertificateNo重命名为"id“或者在它之前创建新的,因为网格在很多地方都与它一起工作,所以很难在任何地方改变它。
https://stackoverflow.com/questions/14373702
复制相似问题