handontable验证部分不起作用,它正在迭代26,其中相同的代码在其他页面

时间:2016-03-07 11:23:18

标签: jquery model-view-controller handsontable

我无法理解,我的代码在哪里?我已经实现了handontable,一切都工作正常,期望验证,在验证中它是多次迭代。但是要捣蛋25次

大家好,我无法理解,我的代码在哪里?我已经实现了handontable,一切都工作正常,期望验证,在验证中它是多次迭代。但是要捣蛋25次

enter code here
  $(document).ready(function () {
     $('#btnValidateSave').on('click',function () {
     debugger;
    $('#HSTable').handsontable('validateCells', function (isPass) {
        if (isPass) {
            SaveData();
            alert("Saving data");
        }
        else {
            alert("Please enter the data in correctformat");
        }
    });
    //$('#HSTable').handsontable('render');
   });

   $('#btnUpload').click(function () {
     upload();

          })

      });


         function upload()
           {
 var formData = new FormData();
 var totalFiles = document.getElementById("UploadFile").files.length;
 for (var i = 0; i < totalFiles; i++) {
     var file = document.getElementById("UploadFile").files[i];
        formData.append("Document", file);
    }
    $.ajax({
        url: "/BulkUpload/UploadFile",
        type: "POST",
        dataType: "JSON",
        data: formData,
        contentType: false,
        processData: false,
        success: function (result) {
            if (result != null) {
                DataBind(result);
            }
            else
            {

            }
        }
      });
        }


        function DataBind(result) {

     $("#HSTable").handsontable({
    data: result,
     startRows: 100,
    rowHeaders: true,
    colHeaders: ["Agent","Invoice No", "Issue Date", "Passanger",
       "Empno", "ProjectCode", "RequestNo", "RequireDate",
       "AirlineName", "AirLineCode", "Ticket", "Locator", "FlightNO",          "DetpDate",
       "ReturnDate", "ServiceClass", "ServiceType", "TravelType", "TripType", "Sector",
       "OrgnDtn", "Region", "BaseFare", "TotalTax", "ServiceFare", "TotalFare", "Remarks"],
    columns: [
       {data: 'Agent'},
       { data:'InvoiceNo' },
       { data: 'IssueDate' },
       {
           data: 'Passenger',

       },
        {
            data: 'EmpNo',

        },
        {
            data: 'ProjectCode',

        },
        {
            data: 'RequestNo',

        },
       { data:'RequireDate'},
       {data:'AirLineName'},
       { data: 'AirLinecode' },
      { data: 'TicketNo' },
      { data: 'Locator' },
      { data: 'FlightNo' },
      { date: 'DepDate' },
      { date: 'ReturnDate' },
     { data: 'ServiceClass' },
     { data: 'ServiceType' },
     { data: 'TravelType' },
     { data: 'tripType' },
     { data: 'Sector'},
     { data: 'OrgDtn' },
     { data: 'Region' },
     { data: 'BaseFare' },
     { data: 'TotalTax' },
     { data: 'ServiceFee' },
     { data: 'TotalFare' },
     { data: 'Remarks' }

    ],
    colWidths: 85,
       });

      }
       var notEmpty=function(value, callback) {
   if (!value || String(value).length === 0) {
         callback(false);

      }
          else {
    callback(true);
}

};

     var EmailValidator = function (value, callback) {
   if (/.+@@.+/.test(value)) {
    callback(true);
}
else {
    callback(false);
}

           };


   function SaveData() {

var data = [{}];
var $container = document.getElementById('#HSTable');
var colHeaderList = $('#HSTable').handsontable("getColHeader");
var rowHeaderList = $('#HSTable').handsontable("getRowHeader");
var tableData = $('#HSTable').handsontable("getData");
var obj = $('#HSTable').handsontable("getData");

var ObjBulk = [];
debugger;
//for (var i = 0; i < obj.length; i++) {
for(var i=0;i<obj.length;i++){
      var user = new Object();

   user.Agent = obj[i]["0"];
    user.InvoiceNo = obj[i]["1"];       
    user.IssueDate = obj[i]["2"];
    user.Passenger = obj[i]["3"];
    user.EmpNo = obj[i]["4"];
    user.ProjectCode = obj[i]["5"];
    user.RequestNo = obj[i]["6"];
    user.RequireDate = obj[i]["7"];
    user.AirLineName = obj[i]["8"];
    user.AirLineCode = obj[i]["9"];
    user.TicketNo = obj[i]["10"];
    user.Locator = obj[i]["11"];
    user.FlightNo = obj[i]["12"];
    user.DeptDate = obj[i]["13"];
    user.ReturnDate = obj[i]["14"];
    user.ServiceClass = obj[i]["15"];
    user.ServiceType = obj[i]["16"];
    user.TravelType = obj[i]["17"];
    user.Sector = obj[i]["18"];
    user.OrgDtn = obj[i]["19"];
    user.Region = obj[i]["20"];
    user.BaseFare = obj[i]["21"];
    user.TotalTax = obj[i]["22"];
    user.ServiceFee = obj[i]["23"];
    user.TotalTax = obj[i]["24"];
    user.ServiceFee = obj[i]["25"];
    user.TotalFare = obj[i]["26"];
    user.Remarks = obj[i]["27"];
    ObjBulk.push(user);
    }
//};

       $.ajax({
    url: "/BulkUpload/SaveBulkData",
    type: "POST",  
    contentType: "application/json",
    dataType: "JSON",
    data: JSON.stringify(ObjBulk),
    success: function (data) {
        alert(data);
    },
    error: function (xhr) {
        alert(xhr)
    }

      });

    };

1 个答案:

答案 0 :(得分:0)

将emailValidator功能应用于包含电子邮件ID的列。

例如:

columns: [
      {data: 'id', type: 'numeric'},
      {data: 'name.first'},
      {data: 'name.last'},
      {data: 'ip', validator: ipValidatorRegexp, allowInvalid: true},
      {data: 'email', validator: emailValidator, allowInvalid: false}
    ]

您可以参考fiddle for demo