2016-12-29 24 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列)。 我试过table.unbind();table.die(),但这并没有奏效。


我在代码的最后测试:

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

但它没有工作

+3

你有没有读过https://github.com/ejbeaty/CellEdit? 'table.MakeCellsEditable(“摧毁”);' –

+0

哦,还没有看到这个! – Jarla

+0

但是我测试过'table.MakeCellsEditable(“destroy”);'不幸的是它没有工作 – 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的代码和演示。

相关问题