我的服务器端代码我正在尝试导出所选行。导出后,它导出所有记录但我想导出所选记录。对于选择我使用复选框
while( $row=mysqli_fetch_array($queryRecords) )
{
$nestedData=array();
$nestedData[] = "<input type='checkbox' onclick='checkboxfn($(this));'
id='singleBox' value='".
$index."'/>";
$nestedData[] = "<i class='mdi mdi-format-list-bulleted'></i>";
$nestedData[] = $index;
$nestedData[] = $row["Designation"];
$nestedData[] = $row["CompanyName"];
$nestedData[] = $row["PersonalEmail"];
$nestedData[] = $row["PersonalPhone"];
$nestedData[] = $row["PersonalMobile"];
$data[] = $nestedData;
$index++;
}
$json_data = array(
"draw" => 1,
"recordsTotal" => intval( $totalRecords ),
"recordsFiltered" => intval($totalRecords),
"data" => $data // total data array
);
echo json_encode($json_data); // send data as json format
这是我的导出按钮代码。我可以导出所有记录而不选择任何记录,但我无法导出所选记录
dom: 'lBfrtip',
buttons: [
{
extend: 'copyHtml5',
exportOptions: {
columns: [6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21 ]
}
},
{
extend: 'excelHtml5',
text: 'XLS',
exportOptions: {
columns: [6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21]
}
},
{
extend: 'csvHtml5',
exportOptions:
{
columns: [6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21]
}
},
{
extend: 'pdfHtml5',
orientation: 'landscape',
pageSize: 'A0',
exportOptions: {
columns: [7,8,9,10,11,12,13,14,15,16,17,18,19,20,21]
}
},
],
columnDefs: [{
"targets": 5,
"orderable": true,
}]
我的checkboxfn函数
function checkboxfn(t)
{
if (t.is(':checked'))
{
var index = rowIds.indexOf(t[0]['value']);
if (index < 0)
{
rowIds.push(t[0]['value']);
}
}else
{
var index = rowIds.indexOf(t[0]['value']);
if (index > -1) {
rowIds.splice(index, 1);
}
}
答案 0 :(得分:0)
实际上,我在&#34; buttons.html5.min.js&#34;中找到了答案。我必须添加以下代码
对于CSV和复制,请添加以下代码
for(i=0;i<l.length;i++)
{
if(rowIds.length != 0)
{
// I AM GETTING ERROR ON BELOW LINE
var index = rowIds.indexOf(l[i].match(/\d+/)[0]);
console.log("Copy and CSV "+l[i].match(/\d+/)[0]);
console.log("Index "+index);
if (index < 0)
{
//alert("dont export");
}
else
{
l[i]=l[i].substr(l[i].indexOf(b.fieldSeparator) + 1);
temp.push(l[i]);
}
}
else
{
//removing the row id from the contact before export.
l[i]=l[i].substr(l[i].indexOf(b.fieldSeparator) + 1);
temp.push(l[i]);
}
}
并且对于Excel必须添加以下代码
for (var f = 0, h = b.body.length; f < h; f++)
if(rowIds.length != 0)
{
var index = rowIds.indexOf(b.body[f][0]);
console.log("Excel "+b.body[f][0]);
if (index < 0)
{
//alert("dont export");
}
else
{
b.body[f].splice(0, 1);
a += e(b.body[f]);
}
}
else
{
b.body[f].splice(0, 1);
a += e(b.body[f]);
}
}