2016-12-29 18 views
2

私は条件column == 1を持っており、このような場合には、機能MakeCellsEditableと機能myCallbackFunctionが初期化されています。私は何をしたいか実行後にすべての関数を強制終了できますか?

<script src="https://raw.githubusercontent.com/ejbeaty/CellEdit/master/js/dataTables.cellEdit.js"></script> 

$(document).ready(function() { 
    var table = $('#myTable').DataTable(); 
    $('#myTable tbody').on('mousedown', 'td', function() { 
     $('#myTable').data('column', table.cell(this).index().columnVisible); 
    }); 
    if (column == 1) { 
     table.MakeCellsEditable({ 
      "onUpdate": myCallbackFunction 
     }); 
    } 
}); 

function myCallbackFunction(updatedCell, updatedRow, oldValue) { 
    var array = updatedRow.data(); 
    var id = array[0]; 
    var column = $('#myTable').data('column'); 
    console.log("The column is: " + column); 
    jQuery.ajax({ 
     type: "POST", 
     url: "update.php", 
     data: { 
      updatedCell: updatedCell.data(), 
      id: id, 
      column: column, 
     }, 
     cache: false 
    }); 
} 

は、関数が実行された後、あるが、私は彼らを殺したいです。そうでなければ、1回クリックして1列目をクリックすると、すべてのテーブルが編集可能になります(列1だけでなく)。 table.unbind();またはtable.die()を試しましたが、これはうまくいきませんでした。


は、私は、コードの最後にテストした:

function destroyTable() { 
     if ($.fn.DataTable.isDataTable('#myTable')) { 
      table.destroy(); 
      table.MakeCellsEditable("destroy"); 
     } 
    } 

しかし、それは見出しで質問に答えるために

+3

あなたはhttps://github.com/ejbeaty/CellEditを読んでいますか? 'table.MakeCellsEditable(" destroy ");' –

+0

ああこれを見たことがない! – Jarla

+0

しかし、私は 'table.MakeCellsEditableが(「破壊する」)を試験;'それは、残念ながら、あなたがそれを受け入れることができるように – Jarla

答えて

1

をうまくいかなかった:うん:

function thiswilljustworkonce(){ 
alert("once"); 
this.thiswilljustworkonce=function(){}; 
} 

thiswilljustworkonce(); 
thiswilljustworkonce(); 
1

CellEditプラグインの場合は、columnsオプションを使用して、編集可能な列を指定します。イベントハンドラを削除する必要はありません。

var table = $('#example').DataTable(); 

function myCallbackFunction (updatedCell, updatedRow, oldValue) { 
    console.log("The new value for the cell is: " + updatedCell.data()); 
    console.log("The values for each cell in that row are: " + updatedRow.data()); 
} 

table.MakeCellsEditable({ 
    "columns": [0], 
    "onUpdate": myCallbackFunction, 
    "confirmationButton": true 
}); 

コードとデモンストレーションについては、this exampleを参照してください。

関連する問題