英文:
DataTables cannot read property 'row' of undefined
问题
不能读取未定义的属性'row'
$.ajax({
// ...(你的其他Ajax设置)
success:function(data){
console.log('检查数据', data); // 请参见下面的截图
console.log('检查行', row); // 请参见下面的截图
table.cell( row, 0 ).data( data.data.seqNo );
table.cell( row, 1 ).data( data.data.name );
table.cell( row, 2 ).data( data.data.customer.name );
table.cell( row, 3 ).data( data.data.province.name );
table.cell( row, 4 ).data( data.data.city.name );
table.cell( row, 5 ).data( data.data.address );
table.cell( row, 6 ).data( data.data.postalCode );
$('.editModalLocation').modal('hide');
$(".customerMessage").append('<div class="alert alert-success fade in">'+data.success+'</div>').hide(4000);
}
});
表格
<table id="dataTableLocations" class="table table-striped table-bordered">
<thead>
<tr>
<th width="30">Seq No.</th>
<th>Name</th>
<th>Customer</th>
<th>Province</th>
<th>City</th>
<th>Address</th>
<th>Postal Code</th>
<th width="120">Options</th>
</tr>
</thead>
<tbody id="table_dataLocations"></tbody>
</table>
屏幕截图
有人能告诉我这段代码有什么问题吗?
英文:
I try to show my new data in table after update gets successful but it returning
> Cannot read property 'row' of undefined
Code
Script
<script>
$(function() {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
var table = $("#dataTableLocations").DataTable();
$('#dataTableLocations').on('click', '.locationUpdate', function(e){
e.preventDefault();
var ordID = $(this).data('id');
var row = $(this).closest('tr');
var province_id = $(this).closest("form").find("#province_idLocationUpdate").val();
var city_id = $(this).closest("form").find("#city_idLocationUpdate").val();
var name = $(this).closest("form").find("#nameLocUpdate").val();
var address = $(this).closest("form").find("#addressLocationUpdate").val();
var postalCode = $(this).closest("form").find("#postalCodeUpdate").val();
var seqNo = $(this).closest("form").find("#seqNoUpdate").val();
$.ajax({
type:'PUT',
url:'{{url('dashboard/customer-locations')}}/'+ordID,
data:{
province_id:province_id,
city_id:city_id,
name:name,
address:address,
postalCode:postalCode,
seqNo:seqNo
},
success:function(data){
console.log('check data', data); // see the screenshot below
console.log('check row', row); // see the screenshot below
table.cell( row, 0 ).data( data.data.seqNo );
table.cell( row, 1 ).data( data.data.name );
table.cell( row, 2 ).data( data.data.customer.name );
table.cell( row, 3 ).data( data.data.province.name );
table.cell( row, 4 ).data( data.data.city.name );
table.cell( row, 5 ).data( data.data.address );
table.cell( row, 6 ).data( data.data.postalCode );
$('.editModalLocation').modal('hide');
$(".customerMessage").append('<div class="alert alert-success fade in">'+data.success+'</div>').hide(4000);
}
});
});
});
</script>
Table
<table id="dataTableLocations" class="table table-striped table-bordered">
<thead>
<tr>
<th width="30">Seq No.</th>
<th>Name</th>
<th>Customer</th>
<th>Province</th>
<th>City</th>
<th>Address</th>
<th>Postal Code</th>
<th width="120">Options</th>
</tr>
</thead>
<tbody id="table_dataLocations"></tbody>
</table>
Screenshot
Can anyone please tell me what's wrong with this code?
答案1
得分: 1
尝试更改此代码部分:
var row = $(this).closest('tr')
更改为
var row = table.row(this);
英文:
Try change this:
> var row = $(this).closest('tr')
change to
> var row = table.row(this);
答案2
得分: -1
已解决
我将我的更新代码移到了父脚本中,其中数据正在返回,并将它们合并成了一个,现在我的代码按照预期工作。
英文:
Solved
I moved my update code to parent script where the data was returning and merged them all in one now my code works as it supposed to.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论