当单击数据表行时出现错误:“无法读取未定义的属性'1'”

时间:2019-05-04 10:15:54

标签: javascript c# jquery asp.net-mvc-4 datatables

我使用实体框架6在asp.net MVC 4中开发Web应用程序。
在此页面上,当我单击供应商时,从数据库动态生成的数据表。
我想在单击数据表行时弹出一个窗口,但是当我单击表行时出现错误。

这是我的视图代码

$(document).ready(function() {
  $.fn.ABC = function() {
    var selectedValue = $("#SCODE option:selected").val();
    $.ajax({
      type: "POST",
      url: '@Url.Action("GetPendingGrnDetail", "Purchase")',
      contentType: "application/json; charset=utf-8",
      data: JSON.stringify({
        'scode': selectedValue
      }),
      success: function(Orderlist) {
        if (Object.keys(Orderlist).length > 0) {
          $('#tblbody').text("");
          BindData(Orderlist);
        } else {
          $('#tblbody').text("");
          var text = "No Data found.";
          $('#tblbody').append(
            '<tr class="odd"><td valign="top" colspan="14" class="dataTables_empty">' +
            text + '</td></tr>');
        }
      },
      error: function() {
        alert('Error. Please try again.');
      }
    });
  };
  var BindData = function(response) {
    $('#example').DataTable({
      data: response,
      responsive: false,
      "pagingType": "full_numbers",
      "lengthMenu": [
        [10, 25, 50, -1],
        [10, 25, 50, "All"]
      ],
      columns: [{
          'data': 'PONO'
        },
        {
          'data': 'POLI'
        },
        {
          'data': 'ITEMCODE'
        },
        {
          'data': 'DESCRIPTION'
        },
        {
          'data': 'Unit'
        },
        {
          'data': 'POQty'
        },
        {
          'data': 'InQty'
        },
        {
          'data': 'Pending'
        },
        {
          'data': 'AcceptQty'
        },
        {
          'data': 'RejectQty'
        },
        {
          'data': 'Remarks'
        },
      ],
      language: {
        search: "_INPUT_",
        searchPlaceholder: "Search records",
      },
      dom: 'Bfrtip',
      buttons: [
        'copy', 'excel', 'pdf'
      ]
    });
  }
  $("#SCODE").on("change", function() {
    $('#tblbody').empty();
    $('#example').DataTable().destroy();
    $.fn.ABC();
  });
});
var table = $('#example').DataTable();
$('#example').on('click', 'tr', function() {
  var name = $('td', this).eq().text();
  console.log(table.row(this).data());
  $("#pono").text(table.row(this).data()[1]);
  $("#poli").text(table.row(this).data()[3]);
  $("#supinvno").text(table.row(this).data()[6]);
  $("#supinvdt").text(table.row(this).data()[7]);
  $("#itemcode").text(table.row(this).data()[10]);
  $("#inqty").text(table.row(this).data()[12]);
  $("#unit").text(table.row(this).data()[14]);
  //$("#machi").text(table.row(this).data()[13]);

  //$("#PQTY").val(table.row(this).data()[16]);
  //$("#PRCReadyDT").val(table.row(this).data()[17]);
  //$("#REMARKS").val(table.row(this).data()[18]);
  $('#DescModal').modal("show");
});

$('#modalsave').click(function() {
  var datavalue = {
    OANO: $('#oano').text(),
    ID: $('#idd').text(),
    MOULDCODE: $('#dieno').text(),
    Diename: $('#metal').text(),
    ORDERQTY: $('#orderqty').text(),
    PQTY: $('#PQTY').val(),
    isMachining: ($('#machi').text() == 'Yes' ? 1 : 0),
    REMARKS: $('#REMARKS').val(),
    PRCReadyDT: new Date($('#PRCReadyDT').val())
  }
  console.log("sending record", datavalue);
  $.ajax({
    type: "POST",
    url: '@Url.Action("PendingPRCList", "PRC")',
    contentType: "application/json; charset=utf-8",
    data: JSON.stringify(datavalue),
    success: function(data) {
      if (data == 1 || data == -1) {
        toastr.success('', 'PRC Generated Successfully!!', {
          timeOut: 5000,
          fadeOut: 5000,
          onHidden: function() {
            window.location.reload();
          }
        });
      } else {
        toastr.error('', 'Something Went To Wrong in Generate PRC', {
          timeOut: 5000,
          fadeOut: 5000,
          onHidden: function() {
            window.location.reload();
          }
        });
      }
    },
    //error: function () { alert('Error. Please try again.'); }
  });
});
<div class="card">
  <div class="card-header card-header-primary card-header-icon">
    <div class="card-icon">
      <i class="material-icons">sort</i>
    </div>
    <h4 class="card-title">Filter</h4>
    <div class="row">
      <div class="col-lg-8">
        <div class="col-lg-12">
          <div class="form-group">
            @Html.DropDownList("SCODE", Session["supplier"] as SelectList, "-- Select Supplier-- ", htmlAttributes: new { @class = "form-control js-example-basic-single" })
          </div>
        </div>
        <div class="row">
          <div class="col-md-6">
            <div class="form-group">
              <label for="" class="bmd-label-floating">Supplier Challan/Invoice No.</label> @Html.EditorFor(model => model.SupInvNo, new { htmlAttributes = new { @class = "form-control", Title = "Challan Date" } }) @Html.ValidationMessageFor(model =>
              model.SupInvNo, "", new { @class = "text-danger" })
            </div>
          </div>
          <div class="col-md-6">
            <div class="form-group">
              <label for="" class="bmd-label-floating">Invoice Date</label> @Html.EditorFor(model => model.SupInvDT, new { htmlAttributes = new { @class = "form-control datepicker", Title = "Invoice/Challan Date", Value = DateTime.Today.ToShortDateString()
              } }) @Html.ValidationMessageFor(model => model.SupInvDT, "", new { @class = "text-danger" })
            </div>
          </div>
        </div>
      </div>
      <div class="col-lg-4">
        <div class="col-md-12">
          <div class="form-group">
            <label for="" class="bmd-label-floating">GRN Number</label> @Html.EditorFor(model => model.GRNNO, new { htmlAttributes = new { @class = "form-control", Title = "GRN Number", @readonly = true, @Value = Session["grnno"] } }) @Html.ValidationMessageFor(model
            => model.GRNNO, "", new { @class = "text-danger" })
          </div>
        </div>
        @{ if (Convert.ToInt32(Session["DesignationID"])
        <=3 ) { <div class="col-md-12" style="margin-top:15px;">
          <div class="form-group">
            <label for="" class="bmd-label-floating">GRN Date</label> @Html.EditorFor(model => model.GRNDT, new { htmlAttributes = new { @class = "form-control datepicker", Title = "GRN Date", Value = DateTime.Today.ToShortDateString() } }) @Html.ValidationMessageFor(model
            => model.GRNDT, "", new { @class = "text-danger" })
          </div>
      </div>
      } else {
      <div class="col-md-12" style="margin-top:15px;">
        <div class="form-group">
          <label for="" class="bmd-label-floating">GRN Date</label> @Html.EditorFor(model => model.GRNDT, new { htmlAttributes = new { @class = "form-control datepicker", @readonly = true, Title = "GRN Date", Value = DateTime.Today.ToShortDateString()
          } }) @Html.ValidationMessageFor(model => model.GRNDT, "", new { @class = "text-danger" })
        </div>
      </div>
      } }
    </div>
  </div>
</div>
</div>
<div class="card">
  <div class="card-header card-header-primary card-header-icon">
    <div class="card-icon">
      <i class="material-icons">assignment</i>
    </div>
    <h4 class="card-title">Pending GRN Details</h4>
  </div>
  <div class="card-body">
    <div class="material-datatables">
      <table id="example" class="table table-striped table-bordered table-responsive table-hover nowrap text-center" cellspacing="0" width="100%" style="width:100%">
        <thead>
          <tr>
            <th nowrap>
              @Html.DisplayName("PONO")
            </th>
            <th nowrap>
              @Html.DisplayName("POLI")
            </th>
            <th nowrap>
              @Html.DisplayName("ITEMCODE")
            </th>
            <th nowrap>
              @Html.DisplayName("DESCRIPTION")
            </th>
            <th nowrap>
              @Html.DisplayName("Unit")
            </th>
            <th nowrap>
              @Html.DisplayName("POQty")
            </th>
            <th nowrap>
              @Html.DisplayName("InQty")
            </th>
            <th nowrap>
              @Html.DisplayName("Pending")
            </th>
            <th nowrap>
              @Html.DisplayName("AccesptQty")
            </th>
            <th nowrap>
              @Html.DisplayName("RejectQty")
            </th>
            <th nowrap>
              @Html.DisplayName("Remarks")
            </th>
          </tr>
        </thead>
        <tbody id="tblbody" style="overflow-x:scroll;"></tbody>
      </table>
    </div>
  </div>
</div>
<div class="modal fade" id="DescModal" role="dialog">
  <div class="modal-dialog dialog-md">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
        <h3 class="modal-title">Generate GRN</h3>
      </div>
      <div class="modal-body">
        <div class="row justify-content-center">
          <div class="col-lg-10">
            <div class="form-group">
              <label for="" class="bmd-label-floating">Accept QTY</label> @Html.Editor("AcceptQty", new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessage("AcceptQty", "", new { @class = "text-danger" })
            </div>
          </div>
          <div class="col-lg-10">
            <div class="form-group">
              <label for="" class="bmd-label-floating">Reject Qty</label> @Html.Editor("RejectQty", new { htmlAttributes = new { @class = "form-control datepicker" } }) @Html.ValidationMessage("RejectQty", "", new { @class = "text-danger" })
            </div>
          </div>
          <div class="col-lg-10">
            <div class="form-group">
              <label for="" class="bmd-label-floating">Remarks</label> @Html.Editor("REMARKS", new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessage("REMARKS", "", new { @class = "text-danger" })
            </div>
          </div>
        </div>
        <div class="modal-footer">
          <button id="modalsave" type="submit" class="btn btn-next btn-fill btn-rose btn-wd" data-dismiss="modal">Generate!</button>
        </div>
        <hr />
        <div style="background-color:#f7f7f7;padding:10px 15px;">
          <div class="row">
            <table>
              <tr>
                <td>
                  <label id="" class="bmd-label-floating">PO Number:</label>
                </td>
                <td>
                  <label id="pono" class="detaillbl"></label>
                </td>
              </tr>
              <tr>
                <td>
                  <label id="" class="bmd-label-floating">PO Line No:</label>
                </td>
                <td>
                  <label id="poli" class="detaillbl"></label>
                </td>
              </tr>
              <tr>
                <td>
                  <label id="" class="bmd-label-floating">Supplier Invoice No:</label>
                </td>
                <td>
                  <label id="supinvno" class="detaillbl"></label>
                </td>
              </tr>
              <tr>
                <td>
                  <label id="" class="bmd-label-floating">Supplier Invoice Date:</label>
                </td>
                <td>
                  <label id="supinvdt" class="detaillbl"></label>
                </td>
              </tr>
              <tr>
                <td>
                  <label id="" class="bmd-label-floating">ItemCode:</label>
                </td>
                <td>
                  <label id="itemcode" class="detaillbl"></label>
                </td>
              </tr>
              <tr>
                <td>
                  <label id="" class="bmd-label-floating">In Qty:</label>
                </td>
                <td>
                  <label id="inqty" class="detaillbl"></label>
                </td>
              </tr>
              <tr>
                <td>
                  <label id="" class="bmd-label-floating">Unit:</label>
                </td>
                <td>
                  <label id="unit" class="detaillbl"></label>
                </td>
              </tr>
            </table>
          </div>
        </div>
      </div>
      <hr />
    </div>
    <!-- /.modal-content -->
  </div>
  <!-- /.modal-dialog -->
</div>

有人可以帮我吗

0 个答案:

没有答案