如何在数据表1.9.4中进行空字段验证?

时间:2013-12-03 13:01:56

标签: javascript jquery twitter-bootstrap datatables alertdialog

当点击“AddNew”按钮时,datatable正在创建一个空/空值的新记录。如何避免这种情况?

注意: 我在bootstrap portlet box layout.how中使用数据表在数据表中添加空值时显示警告错误消息??

1 个答案:

答案 0 :(得分:1)

在编辑点击事件中取样link我为第一列添加了简单的空字段验证。

$('#exampleTable a.edit').live('click', function (e) {    
e.preventDefault();      
var nRow = $(this).parents('tr')[0];   
if (nEditing !== null && nEditing != nRow) {
    /*if Currently editing - but not this row - restore the old before continuing to edit mode */
    restoreRow(oTable, nEditing);
    editRow(oTable, nRow);
    nEditing = nRow;
} else if (nEditing == nRow && this.innerHTML == "Save") {
    /* else Editing this row and want to save it */
   var newEntry = $((oTable.fnGetData(nRow)).edit).attr("data-mode") == "new";
   var jqValInputs = $('input', nEditing);
   if(jqValInputs[0].value.length == 0)
   {
       alert("Name cannot be empty");
       return false;
   }
    saveRow(oTable, nEditing);
    nEditing = null;
    oTable.fnUpdate(data.id, nRow, 0, false);
 } else {
    editRow(oTable, nRow);
    nEditing = nRow;
}
});