数据表在删除行时显示警告

时间:2015-12-14 15:35:52

标签: javascript jquery datatables

为了从Datatables实例中删除选定的行,我可以使用:

var rows = table
    .rows( '.selected' )
    .remove()
    .draw();

但是,我还想向用户显示一条警告消息,如下所示:

var rows = table
    .rows( '.selected' )
    .showWarning('Are you sure you want to delete the selected rows?')
    .remove()
    .draw();

如何在删除行之前向用户显示警告?

1 个答案:

答案 0 :(得分:2)

您可以使用confirm(),如下所示:

if(confirm('Are you sure you want to delete the selected rows?')){
   var rows = table
      .rows( '.selected' )
      .remove()
      .draw();
}