我有一个php创建 CSV 文件的页面,然后浏览器会自动下载该文件。这是一个带有示例数据的版本 - 效果很好。
<?php
$cars = array(
array("Volvo",22,18),
array("BMW",15,13),
array("Saab",5,2),
array("Land Rover",17,15)
);
// output headers so that the file is downloaded rather than displayed
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=csvfile.csv');
// create a file pointer connected to the output stream
$output = fopen('php://output', 'w');
// output the column headings
fputcsv($output, array('Car', 'Year', 'Miles' ));
//Loop through the array and add to the csv
foreach ($cars as $row) {
fputcsv($output, $row);
}
?>
Run Code Online (Sandbox Code Playgroud)
我希望能够从另一个页面运行它,ajax以便用户可以在 …
我正在尝试使用DataTable插件在我的表中创建一个列,该插件是使用前两列中的值计算的.
像这样...... .. (价格)(QTY)=总计
|| Price || QTY || Total||
==========================
|| 5 || 2 || 10 ||
|| 10 || 3 || 30 ||
|| 4 || 1 || 4 ||
Run Code Online (Sandbox Code Playgroud)
我觉得它应该很简单,但我无法让它发挥作用.这是我试图遵循的类似问题.
var table = $('#tempPOs').DataTable( {
dom: 'frtip', //Bfrtip (removed the B to get rid of the buttons)
ajax: '/inventory/DTResources/php/table.tempPOs.php',
columns: [
{ "data": "pmkPart" },
{ "data": "PartNumber" },
{ "data": "Description" },
{ "data": "fnkManufacturer" },
{ "data": "Notes" },
{ "data": "EachPrice", render: …Run Code Online (Sandbox Code Playgroud) 我有一个DataTables表,我希望能够在单击tr时获得第一个td的值.我已将此td的可见性设置为false.
编辑:因为到目前为止两个答案假设我可以点击我想要的单元格. 我不能点击我需要的值的单元格.
$(document).ready(function() {
var table = $('#example').DataTable({
select: false,
"columnDefs": [{
className: "ID",
"targets":[0],
"visible": false,
"searchable":false
}]
});//End of create main table
$('#example tbody').on( 'click', 'tr', function () {
cellValue = //code to get the cell value
console.log(cellValue);
});
});
Run Code Online (Sandbox Code Playgroud)
我已经看过许多使用旧的DataTables方法fnGetColumnData的例子,但我不确定如何实现更新的cell.data().
谁能帮我吗?
我需要在表中添加一个可编辑列。这是我当前创建表的方式。数据来自 Javascript 数组,并且正在变化(这就是为什么我在表定义中有“destroy: true”)。我希望 QTY 列的默认值为 1,但允许用户输入自己的数字 - 然后我需要能够在提交表单时检索该值。
var table2 = $('#example').DataTable( {
select: false,
data: addedRows,
destroy: true,
columns: [
{ title: "ID" },
{ title: "Name" },
{ title: "Position" },
{ title: "Office" },
{ title: "Extn." },
{ title: "Start date" },
{ title: "Salary" },
{ title: "QTY" }
],
"columnDefs": [{
className: "ID",
"targets":[0],
"visible": false,
"searchable":false
}],
"language": {
"emptyTable": "Select items from the table above"
}
});
Run Code Online (Sandbox Code Playgroud)
谁能帮我吗?既要创建可编辑的列,又要在提交时获取该数据?
谢谢