javascript - How to use Datatables column data (done in js) in action button url's last segment?
问题描述
How to use Datatables column data (done in js) in action button url's last segment
I have a column data that gives the output of from a database table. I want to one of the columns data at the last segment of the url. My provided attachment photo shows the details. If anyone could help
data: 'file_id' to be used in url
<script type="text/javascript">
$(document).ready(function(){
$('#empTable').DataTable({
'processing': true,
'serverSide': true,
'serverMethod': 'post',
'ajax': {
'url':'<?=base_url()?>admin/Employee/empList'
},
dom: 'Bfrtip',
buttons: [
{extend: 'copy', attr: {id: 'allan'}}, 'csv', 'excel', 'pdf'
],
'columns': [
{ data: 'id_no' },
{ data: 'customer_name' },
{ data: 'seized_remarks' },
{ data: 'seized_date' },
{ data: 'release_probability' },
{ data: 'file_id' },
{ data: null,
defaultContent: '<a href="https://202.40.176.13/mahindra_portal/admin/seized_vehicles/individual_view/$file_id"><button ><i class="fa fa-search"></i></button></a> <input type="button" id="go" value="Upload Image" /> <button>Edit</button>' },
]
});
});
</script>
解决方案
你可以做的是定义一个渲染函数,例如:
$('#empTable').DataTable({
'processing': true,
'serverSide': true,
'serverMethod': 'post',
'ajax': {
'url':'<?=base_url()?>admin/Employee/empList'
},
dom: 'Bfrtip',
buttons: [
{extend: 'copy', attr: {id: 'allan'}}, 'csv', 'excel', 'pdf'
],
'columns': [
{ data: 'id_no' },
{ data: 'customer_name' },
{ data: 'seized_remarks' },
{ data: 'seized_date' },
{ data: 'release_probability' },
{ data: 'file_id' },
{ data: null,
render(data) {
return `<a href="https://202.40.176.13/mahindra_portal/admin/seized_vehicles/individual_view/${data.file_id}"><button ><i class="fa fa-search"></i></button></a> <input type="button" id="go" value="Upload Image" /> <button>Edit</button>`;
}
},
]
});
然后,这使您可以访问data
对象中的任何内容。 请参阅文档
推荐阅读
- c - 热设置 termcap 能力'bw'标志?
- .net - OData 和 ElasticSearch 之间的适配器
- java - 使用java生成HmacSHA256时密钥可以为空吗
- swift - UISearchBar Filter UITableView with NSPredicate filter from the array of dictionary with multiple Keys
- javascript - 为移动设备实现切换菜单,但整个导航栏是可点击的,我只想点击按钮
- python-3.x - 如何为 CSV 文件中的列值绘制多条折线图?
- maven - Maven:强制所有子目录都是聚合器 pom 中的模块
- php - 使用 wp_remote_post() 的活动活动 API 403 错误;
- c# - 用 InnerException c# 抛出异常
- android - 无法扫描wifi结果