如何在 DataTables 按钮中设置 href?
How to set the href in a DataTables button?
我使用 DataTables 来格式化我的表格。我也使用他们的按钮插件。我正在尝试创建一个自定义按钮以重定向到另一个页面,我将在其中创建一个 Excel 文件以供下载。我只是不确定如何设置 href
。我试过这个:
$.fn.dataTable.ext.buttons.export =
{
className: 'buttons-alert',
text: "Export All Test III",
action: function (e, dt, node, config)
{
var SearchData = dt.rows({ filter: 'applied' }).data();
var OrderData = dt.order();
alert("Test Data for Searching: " + SearchData);
alert("Test Data for Ordering: " + OrderData);
},
href: './AjaxHandler.php'
};
href
被忽略且未设置。我需要设置 href
。
我该怎么做?
我可以在 Firefox 的 Dev Tools 中看到它有 属性,但它设置为 # 如下:
编辑
从那以后,我尝试在初始化后设置 href
,如下所示:
$('.dt-button.buttons-alert').attr('href', './AjaxHandler.php');
document.querySelector('.buttons-alert').setAttribute('href', './AjaxHandler.php');
这些都没有,但是 href
仍然只显示 #.
dataTables 的选项中没有 "href"。
按钮只有这些选项可以使用:
https://datatables.net/reference/option/#buttons
我已经开始工作了。我仍然无法在按钮中设置 href
。我能做的是:
$.fn.dataTable.ext.buttons.export =
{
className: 'buttons-alert',
id: 'ExportButton',
text: "Export All Test III",
action: function (e, dt, node, config)
{
//This will send the page to the location specified
window.location.href = './AjaxHandler.php';
}
};
尽管它以不同的方式完成,但它完成了同样的事情。
以下是我为解决此问题所做的工作。这会将我的 "Add record" 按钮放入 DataTable DOM
$('#myTable').DataTable({
...,
buttons: [
{
text: '<i class="fa fa-plus"></i>',
className: 'btn btn-default btnAddJob',
titleAttr: 'Add a new record',
init: function (dt, node, config) {
$(node).attr('href', 'put/your/href/here')
}
}
]
})
我使用 DataTables 来格式化我的表格。我也使用他们的按钮插件。我正在尝试创建一个自定义按钮以重定向到另一个页面,我将在其中创建一个 Excel 文件以供下载。我只是不确定如何设置 href
。我试过这个:
$.fn.dataTable.ext.buttons.export =
{
className: 'buttons-alert',
text: "Export All Test III",
action: function (e, dt, node, config)
{
var SearchData = dt.rows({ filter: 'applied' }).data();
var OrderData = dt.order();
alert("Test Data for Searching: " + SearchData);
alert("Test Data for Ordering: " + OrderData);
},
href: './AjaxHandler.php'
};
href
被忽略且未设置。我需要设置 href
。
我该怎么做?
我可以在 Firefox 的 Dev Tools 中看到它有 属性,但它设置为 # 如下:
编辑
从那以后,我尝试在初始化后设置 href
,如下所示:
$('.dt-button.buttons-alert').attr('href', './AjaxHandler.php');
document.querySelector('.buttons-alert').setAttribute('href', './AjaxHandler.php');
这些都没有,但是 href
仍然只显示 #.
dataTables 的选项中没有 "href"。 按钮只有这些选项可以使用: https://datatables.net/reference/option/#buttons
我已经开始工作了。我仍然无法在按钮中设置 href
。我能做的是:
$.fn.dataTable.ext.buttons.export =
{
className: 'buttons-alert',
id: 'ExportButton',
text: "Export All Test III",
action: function (e, dt, node, config)
{
//This will send the page to the location specified
window.location.href = './AjaxHandler.php';
}
};
尽管它以不同的方式完成,但它完成了同样的事情。
以下是我为解决此问题所做的工作。这会将我的 "Add record" 按钮放入 DataTable DOM
$('#myTable').DataTable({
...,
buttons: [
{
text: '<i class="fa fa-plus"></i>',
className: 'btn btn-default btnAddJob',
titleAttr: 'Add a new record',
init: function (dt, node, config) {
$(node).attr('href', 'put/your/href/here')
}
}
]
})