Javascript 是否有一种方法可以从多个SQL表中提取一个DataTables表?
我使用DataTables在我创建的报告网站中显示数据。我正在创建一个报表生成器,用户可以在其中选择多个表,然后从这些表中选择列作为自定义报表 我想知道的是,是否有一种方法可以对数据表执行此操作。我能够获取自定义报表的表名和列名,但我还无法确定如何将其发送到DataTables。我目前使用服务器端处理,并使用POST向DataTable发送ajax调用 我知道我可以基于选定的表和列在SQL查询中编程,但我似乎不知道如何将数据发送到DataTables 以下是初始化数据表的方法:Javascript 是否有一种方法可以从多个SQL表中提取一个DataTables表?,javascript,php,sql-server,datatables-1.10,Javascript,Php,Sql Server,Datatables 1.10,我使用DataTables在我创建的报告网站中显示数据。我正在创建一个报表生成器,用户可以在其中选择多个表,然后从这些表中选择列作为自定义报表 我想知道的是,是否有一种方法可以对数据表执行此操作。我能够获取自定义报表的表名和列名,但我还无法确定如何将其发送到DataTables。我目前使用服务器端处理,并使用POST向DataTable发送ajax调用 我知道我可以基于选定的表和列在SQL查询中编程,但我似乎不知道如何将数据发送到DataTables 以下是初始化数据表的方法: $(docume
$(document).ready(function ()
{
// Setup - add a text input to each footer cell
$('#DataTable tfoot th').each(function () //creates the search bar as the footer
{
var title = $(this).text();
$(this).html('<input type="text" placeholder="Search ' + title + '" />');
});
var table = $('#DataTable').DataTable({
"lengthMenu": [[25, 50, 75, 100, 150, -1], [25, 50, 75, 100, 150, 'All']],
"dom": '<"top"Bifpl<"clear">>rt<"bottom"ip<"clear">>',
"buttons": [{
extend: 'collection',
text: 'Export',
buttons: ['export', { extend: 'csv',
text: 'Export All To CSV', //Export all to CSV file
action: function (e, dt, node, config)
{
window.location.href = './ServerSide.php?ExportToCSV=Yes';
}
}, 'csv', 'pdf', { extend: 'excel',
text: 'Export Current Page', //Export to Excel only the current page and highlight the first row as headers
exportOptions: {
modifier: {
page: 'current'
}
},
customize: function (xlsx)
{
var sheet = xlsx.xl.worksheets['sheet1.xml'];
$('row:first c', sheet).attr('s', '7');
}
}]
}
],
"fixedHeader": { //Keeps the header and footer visiable at all times
header: true,
footer: true
},
"select": true, //sets the ability to select rows
"processing": true, //shows the "Processing" when working
"serverSide": true, //sends data to the server for processing
"ajax": { //where the data is sent and processed
"url": "./ServerSide.php",
"type": "POST"
},
stateSave: true, //Saves the current state of the page
columnDefs: [{ visible: false, targets: 0}], //Hides the first column the ID column
initComplete: function () //sets the search
{
var api = this.api();
// Apply the search
api.columns().every(function ()
{
var that = this;
$('input', this.footer()).on('keyup change', function (e)
{
if (that.search() !== this.value & e.keyCode == 13) //you have to hit enter for the search to start
{
that
.search(this.value)
.draw();
}
});
});
}
});
});
$.fn.dataTable.ext.buttons.export =
{
className: 'buttons-alert', //Adds the "Export all to Excel" button
id: 'ExportButton',
text: "Export All To Excel",
action: function (e, dt, node, config)
{
window.location.href = './ServerSide.php?ExportToExcel=Yes';
}
};
以下是我目前可以从事的工作:
我不确定其他人是否需要帮助我,但如果我遗漏了什么,请告诉我,我会补充
我需要从所有选定的表和列的所有数据在一个DataTables表在网站上提出。在上面的图像中,我展示了我已经获得了列标题,并为表使用了别名。我正在处理FilterSort.class.pph文件,该文件类似于DataTables中的ssp.class.php,以查看是否可以让它显示表。我找到了它。我仍然在调用正确的DataTables函数,但我没有将数据传递给函数。最后我不得不更新我的ServerSide.php文件和FilterSort.class.php文件。这些是所有其他报表用来将数据从服务器发送到屏幕的报表。经过一些尝试和错误后,我使它工作起来,不需要更改问题中发布的代码中的任何内容。DataTables是一个位于HTML表之上的层。使用PHP构建HTML表,并在页面加载时将DataTable应用于该HTML表。在一个显示器中使用多个DB表的联接查询,或者多次使用datatables并为每个表生成多个datatables。你想做什么还不清楚。