我想在名为“查看服务” 的列中添加自定义按钮,因为我想在该列中显示多个值。如何添加带有自定义内容的自定义按钮以执行自定义功能?当用户单击该按钮时,我想打开一个引导程序模版以查看多个值。我怎样才能做到这一点?我是使用数据表的新手。
我的代码:
$('#appointment-datatable').DataTable({
processing: true,
serverSide: true,
ajax: '/get_appointment_data',
columns: [
{ data: 'id', name: 'id' },
{ data: 'user_type', name: 'user_type' },
{ data: 'firstname', name: 'firstname' },
{ data: 'lastname', name: 'lastname' },
{ data: 'vehiclemodel', name: 'vehiclemodel' },
{ data: 'date', name: 'date' },
{ data: 'time', name: 'time' },
{ data: 'payment_status', name: 'payment_status' },
{ data: 'amount', name: 'amount' },
{ data: null, render: function(data, type, full, meta) {
return '<button class="btn btn-mini btn-primary pull-right"> View Service</button>';
} }
],
dom: 'Bfrtip',
buttons: [
{ extend: 'print' },
{ extend: 'pdf' },
{ extend: 'excel' }
],
});
答案 0 :(得分:0)
您可以执行以下操作:
$(document).ready(function () {
var oTable = $('#myDataTable').dataTable({
// "bServerSide": true,
"sAjaxSource": "fetchUserData.cfm",
"bProcessing": true,
"sPaginationType": "full_numbers",
"aoColumns": [
{ "mData": null },
{ "mData": "Name", "sTitle": "Name" , "sWidth": "20%"},
{ "mData": "UserName", "sTitle": "UserName", "sWidth": "20%" },
{ "mData": "Passowrd","sTitle": "Passowrd", "sWidth": "20%" },
{ "mData": "Email","sTitle": "Email" , "sWidth": "20%"},
{ "mData": "IsActive","sTitle": "IsActive" , "sWidth": "20%" },
{
"mData": null,
"bSortable": false,
"mRender": function (o) { return '<a href=#/' + o.userid + '>' + 'Edit' + '</a>'; }
}
]
});
} );
答案 1 :(得分:0)
尝试此数据表。我添加了“ defaultContent”检查其工作状态-
$('#appointment-datatable').DataTable({
processing: true,
serverSide: true,
ajax: '/get_appointment_data',
columns:
[
{
data: 'id',
name: 'id'
},
{
data: 'user_type',
name: 'user_type'
},
{
data: 'firstname',
name: 'firstname'
},
{
data: 'lastname',
name: 'lastname'
},
{
data: 'vehiclemodel',
name: 'vehiclemodel'
},
{
data: 'date',
name: 'date'
},
{
data: 'time',
name: 'time'
},
{
data: 'payment_status',
name: 'payment_status'
},
{
data: 'amount',
name: 'amount'
},
{
data: null,
"defaultContent": '<button class="btn btn-mini btn-
primary pull-right"> View Service</button>'
}
],
dom: 'Bfrtip',
buttons: [
{
extend: 'print'
},
{
extend: 'pdf'
},
{
extend: 'excel'
}
],
})