首页 > 解决方案 > 未捕获的类型错误:无法读取未定义的属性“req_tanggal”

问题描述

从数据表获取记录以输入文本时出现问题,当我在错误日志中单击数据表中的记录时显示此消息“datatable.js:2274 Uncaught TypeError: Cannot read property 'req_tanggal' of undefined”

这是我的代码:

var tpropen;
var tpropen1;


$(document).ready( function ()
{

 tpropen = $('#tpropen').DataTable({
  "columnDefs":[{ "orderable": false,"className": "select-checkbox","targets": [0],"checkboxes": {"selectRow": true}}],
 "select": {"style": "multi"},
 "order": [[0, "asc"]],
 "sAjaxSource": "/HPR_validate",
 "scrollX": "200px",
 "sAjaxDataProp": "",
 "aoColumns":
 [
 { "mData": "id_header_pr", "defaultContent": ""},
 { "mData": "req_tanggal", "defaultContent": ""},
 { "mData": "kode_pr", "defaultContent": ""},
 { "mData": "jenis_pr", "defaultContent": ""},
 { "mData": "status", "defaultContent": ""}
 ]
 });

 tpropen.on('click', function(e)
 {
 var form = this;
 var rows_selected = tpropen.column(0).checkboxes.selected();
 $('#id_header_pr').val(rows_selected.join(","));
    tpropen1 = $('#tpropen').DataTable().row('.selected').data();

 $('#req_tanggal').val(tpropen1 ['req_tanggal']);  // $('#req_tanggal') this is input text////

 });
 //setInterval (tabelhpropen.ajax.reload, 1000);
 });
<div class="tab-pane active" id="tab_1x">
<div >
<div class="panel panel-default">
<table class="table table-striped table-bordered table-hover" id="tpropen" role="grid" style="width: 100%;" width="100%">
<thead>
<tr>
  <th>id_header_pr</th>
  <th>req_tanggal</th>
  <th>kode_pr</th>
  <th>jenis_pr</th>
  <th>status</th>
</tr>
</thead>
</table>
</div>
</div>
</div>

标签: javascriptjquerydatatable

解决方案


You're trying to use the jQuery #id Selector $('#req_tanggal') but no HTML element has a corresponding id.

Change the th element <th>req_tanggal</th> as follows and it should work.

<th id="req_tanggal"></th>

推荐阅读