0

私はmysqlでeditablegridを使用しています。データをグリッドにバインドして表示します。ただし、グリッドを編集または更新しようとすると、失敗します。

以下は、私のロードデータのコードの一部です。

$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();

以下は、私の update.php スクリプトに値を渡す JavaScript の一部です。

    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); 

今、グリッドを更新できません。

4

3 に答える 3

0

I had the same problem. You have to change in js/demo.js in

function DatabaseGrid() 
{ 
    this.editableGrid = new EditableGrid("HERE!!! Chage to name of your sql table", {...

and also rename your CertificateNo to "id" or make new before it, because the grid works with it on many places, so it's hard to change everywhere.

于 2014-03-17T14:28:34.000 に答える